Select Previously USED (Viewed) Safari Tab (not previous tab)

So if you have a lot of tabs open and are jumping around from tab to tab, you may find it's very easy to forget which tab you were on previously looking at or that there is like 5 tabs between the one you are currently viewing and the other tab you want to look at. Safari has a built in shortcut to go to the previous and next tab, but I thought it would be nice to have a shortcut to jump to the previously viewed tab (similar to ⌘-Tab which activates the previously used application).

For example, this macro ends up being very useful if:

  • You are frequently jumping back and forth between 2 tabs
  • You were on tab 10, then clicked on tab 4 & just want to jump back to tab 10 with a shortcut key
  • You forgot which tab you were previously on.

The macro itself is very simple:

But it is dependent on the variables set with this macro (note that you do not execute this macro yourself, it just sets the TabPrevious variable):

I really like this macro and honestly I think Apple should include this with Safari to begin with but luckily Keyboard Maestro makes it possible!

Hope you like!

  • Kevin

Safari - Select Previously Used Tab.kmmacros (11.5 KB)

5 Likes

Good idea, and it works nicely. Thank you!

Good to hear, thanks!

I tried your macro and when nothing happened with your ⌃⇥ key combination I switched it to ⌃⌥⇧⌘6. Unfortunately this crashes Keyboard Maestro. I’m trying to delete the macro but can’t due to the crash.

As it’s a pretty unusual key combination it’s not a major issue, even so I’d like to remove it.

Any ideas how to do that?

Here’s what the log file says about the problem.

⌘2016-04-01 15:22:33 Execute macro ‘Tab - Select Previously Viewed Tab’ from trigger The Hot Key ⌃Tab is pressed
2016-04-01 15:22:33 Safari Control failed to evaluate TabPrevious
2016-04-01 15:22:35 Execute macro ‘Tab - Select Previously Viewed Tab’ from trigger The Hot Key ⌃Tab is pressed
2016-04-01 15:22:35 Safari Control failed to evaluate TabPrevious
2016-04-01 15:25:11 Invalid Plug In Action with Name Loud Comment
2016-04-01 15:25:11 Invalid Plug In Action with Name Loud Comment
2016-04-01 15:25:11 Invalid Plug In Action with Name Loud Comment
2016-04-01 15:25:11 Invalid Plug In Results Loud Comment
2016-04-01 15:25:11 Invalid Plug In Action with Name Loud Comment
2016-04-01 15:25:17 Execute macro ‘Tab - Select Previously Viewed Tab’ from trigger The Hot Key ⌃⌥⇧⌘6 is pressed
2016-04-01 15:25:17 Safari Control failed to evaluate TabPrevious
2016-04-01 15:25:19 Execute macro ‘Tab - Select Previously Viewed Tab’ from trigger The Hot Key ⌃⌥⇧⌘6 is pressed
2016-04-01 15:25:19 Safari Control failed to evaluate TabPrevious
2016-04-01 15:31:00 Execute macro ‘Bring Application Finder Windows to Front’ from trigger Application ‘Finder’ activates

I installed the macro, but because I already use Command-Tab as a shortcut, I was going to change it. But the moment I select the group containing the macro, KM crashes. Consequently I am unable to use the macro or remove it. Could it have something to do with the fact that I am still using KM 6? And how can I remove the macro?

Well there's 2 things I notice from the log, the first is that

and the other is

So the crash could be due to this Plug-In Action but maybe it's the TabPrevious variable.

The thing to remember is that TabPrevious is a variable set by the macro "Tab - Set Current & Previous Variables" so I'm thinking that maybe the variables aren't being created and so Keyboard Maestro doesn't know what to do.

I attached another macro just to initialize the variables and that should stop the crashing -

Initialize Tab Variables.kmmacros (2.6 KB)

  • So activate this in the status menu (with safari in the front) to make the needed variables. (Open a few tabs in Safari first)
  • Then open a few more tabs in Safari and check your variable list in Keyboard Maestro preferences to make sure TabPrevious exists and contains a number
  • Then try the Select Previously Used Tab Macro.

Afterwards you can just delete this initializer macro. Let me know if that works!

Thanks I did this and it cured the crash problem and allowed me to delete the macro.

Thank you. It works great and taught me things about KM. And if I study it I know I’ll learn even more.

I made it Safari only, just to avoid any potential conflicts with the shortcut, although I hadn’t previously used it.

1 Like

I tried to duplicate this and @pubay’s crash could not even with a cleaned out 6.4.8 install.

If you can send me (email support@stairways.com) the crashlog, perhaps that will shed some light on the issue (although if it is a 6.x issue, I probably wont be able to do anything about it).

OK, after looking at the crash, it appears that the crash is some sort of font or font cache issue, probably related to the curved arrow unicode character (TOP ARC ANTICLOCKWISE ARROW (I wont include it directly here in case it causes a problem for people)) used in the icon for the macro.

My guess would be that @pubay and @duncmac both have the same font installed that has some sort of corruption in it for that character, but I could be wrong.

There is some font issue debugging help from adobe here.

If you need to clear your font cache, I have used FontNuke. And it works to solve some of the issues I have had with font caches.

Following the above suggestions, I validated my fonts, disabled or removed any problematic fonts, and cleared the font cache for good measure, but all to no avail. KM still crashes when selecting the group with this macro.

Did you try a safe boot? The crashreport indicates it is a problem with the unicode engine and reports on the net for similar crashes (with other applications) indicate it is a font issue and safe boot resolves the problem.

If so, then this version:

Safari - Select Previously Used Tab-3.kmmacros (11.4 KB)

which is the same as the first posted version except with the unicode characters removed would likely resolve the problem for you.

I have now tried a safe boot, but it has made no difference to the crashes. However, the new macro does not cause KM to crash, so thank you for that.

This sounds great.

Any way to adapt this to work with Chrome?

Definitely! Chrome and Safari basically have the same macros so you can just copy and paste the macros over to a Chrome group and make the adjustments, should be pretty straightforward!

Glad to hear! Hope you keep learning cause Keyboard Maestro is bomb.com! :stuck_out_tongue_winking_eye:

Kevin, thanks for this great macro. :+1:
This fills a need I have had for some time.

I was able to modify it to work with all three of the major Browsers: Safari, Chrome, and FireFox. However, it does not handle use with multiple Browsers at the same time. I've got to make more mods to handle that. When I get that done, and some more testing, I'll post my version.

But, for my workflow, I rarely have more than one Browser open at a time. So this is working well for me.

Unless I run into unforeseen issues, I should have something ready to upload tomorrow.

I appreciate that! I really like this macro and glad to see your getting as much use out of it as I do, looking forward to seeing your mods!

1 Like

Kevin, thanks again for your macros.

You can see my mods here:
Macro Set: Toggle Between Browser Tabs

1 Like