Closing open safari tabs after x amount of time passes

Hello all, I'd reached a point of exasperation with myself over the frustration of attempting to do something simple and getting sidetracked by the distraction created by a previously open tab.

Wondering if there could be a script to automatically close safari tabs after a set duration of time passes. Maybe a script that simply runs the close all tabs after a set period of time elapses after not using safari. it could be worth it for productivities sake to simply have tabs auto-close themselves.

I'm new to Keyboard Maestro, did do some searching on this forum and didn't come up with much.

Thanks in advance!

Hello OlivetoHomeTeam,
welcome to the forum.

So, you have multiple tabs open in Safari then we need to clarify some things about what you want:

  1. you switch to a new tab and after a fixed amount of time you want the "close other tabs" menu choice to be triggered. (there is no "close all tabs") as far as I know.

  2. you switch to another application. Safari is still running in the background and after a fixed amount of time you want to "close all windows" or quit safari (?)

in case you want to close tabs and not windows do you have cases when you have multiple windows with multiple tabs ?

Here is an untested workflow to do this:

  1. Create a Macro that is triggered when Safari deactivates:
    • image
    • Set a KM Global Variable to the current TIME()
    • Enable the Macro created in Step 2
  2. Create another Macro using a Periodic trigger.
    • While you can set this to a number of seconds, I would not use less than 1 minute
    • Compare the current TIME() with the KM Global variable in Step 1
    • Disable this Macro

There are probably other Actions you will want to include, but this should give you a rough idea of how to design a Macro to achieve your objectives.


1 Like

Hi Joseki,
The second scenario you paint is more what I’m looking for.
I’m simply tired of being distracted by previously left open tabs. Yes I could discipline myself to close them but thought an automation might be a useful help.
Thanks for the reply!

1 Like

Thank you JMIchaelTX!
I'll give it a go. Much appreciated!

1 Like