1

There was an older post about this question (link below) from a few years back but I'm wondering if that process no longer works due to iCloud bookmarks, Safari 12, new MacOS etc.

What I would like to do is create a keyboard shortcut for the "Add Bookmarks for These (XX) Tabs..." in a current window of Safari. The System Preferences > Keyboard > Shortcuts doesn't work since the menu label has to be exact and the tab number variable needs to change to match the number of tabs each time. I did do a test with 5 in there and that works for an instance with 5 tabs. Not sure if there is a variable that can be written in there that knows it needs to change.

If not through system settings, assuming it would need to be something like an Apple Script which would work as I'm trying to use Stream Deck to set a button to fire the script.

Adding Bookmarks for multiple tabs in Safari with a keyboard shortcut

0

OK, so the AppleScript required to click that menu item is quite simple:

click menu item 8 of menu 1 of menu bar item "Bookmarks" of menu bar 1

To come up with this particular incantation I used UI Browser.app (there's a free Trial). In UI Browser.app choose your Target app, use the column browse to find the menu item you are interested in, then use the AppleScript dropdown to copy the required snippet to your clipboard (or press Alt+Cmd+T).

UI Browser hierarchy view

I made a small edit to the snippet to reference only the Bookmarks menu item by name.

The AppleScript snippet needs to be dressed up a little more to be useful:

activate application "Safari"
tell application "System Events"
    tell process "Safari"
        click menu item 8 of menu 1 of menu bar item "Bookmarks" of menu bar 1
    end tell
end tell

The works for both Safari and Safari Technology Preview, which is nice.

Running this in, say, macOS Script Editor.app will remotely click the referenced menu item and display the expected conformation dialog.

Safari Add bookmarks dialog

Note: you could add additional AppleScript to manipulate and/or dismiss the confirmation dialog; I'll leave such changes as an exercise for the reader.

Finally, we need to add a shortcut key to access the menu. There are a number of different ways to do this and choice will depend on personal preference and/or software at hand:

  1. Alfred: workflow with NSAppleScript Action + Hotkey Trigger
  2. Keyboard Maestro: AppleScript Action + hot key trigger
  3. Automator: Service + Shortcut key via macOS System Preferences (see this answer)
  4. FastScripts Lite (free for up to 10 shortcut keys): shortcut

Note: it is no longer possible to assign a shortcut key to an item in the macOS Script menu, so I've not included that method of calling the script.

The last of the options above, FastScripts Lite, is the one that comes for free, and also the easiest method, so I'll use it in this answer.

Enter the above "activate...end tell" snippet into macOS Script Editor.app and save the resulting script to ~/Library/Scripts/Applications/Safari/Save Bookmarks for Current Window Tabs.scpt.

In FastScripts Lite.app you'll now have a menu item that is effectively an alias for Safari's "Add Bookmarks for These X Tabs..." menu item, and that can be assigned a shortcut key using FastScripts Lite.app > Preferences > Script Shortcuts.

FastScripts Lite script shortcuts preferences

  • 1
    Matt thank you! I didn't get a notification that you posted this and just saw when I came to add a new comment. Since I use Keyboard Maestro as well as AppleScript and then a StreamDeck device I posted on KM for some advice and got an Apple Script a bit similar to what you generated. I wanted to post it here as an alternative, not my code but it works so I'll just link to KM site where it lives. Your code looks a little cleaner! forum.keyboardmaestro.com/t/… – Clif Watson Jan 4 at 17:58
  • 1
    @ClifWatson Why don't you add your solution as another answer, it might get you some upvotes over time. Just make sure it stands on its own so people can get all the information the need directly on AD, without having to browse to another page. – nohillside Jan 4 at 18:24
  • @ClifWatson happy you're sorted! Whichever way you choose. Also, you should have said you were using an Extension that no longer works. You can get it working using like so: georgegarside.com/blog/macos/… – Matt Sephton Jan 5 at 0:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .