MacOS – Assign keyboard shortcut to Safari Extensions

macbook promacossafari

Is there a place in safari that allows user to assign keyboard shortcut for extensions?

For more specific information, I am trying to assign a shortcut key for this extension: Recent Tab list

However I did not find shortcut customization page on its page. So I am experimenting whether there is such a customization page at the safari level. Any advice is appreciated.

I am using MacBook Pro with OS X Sierra 10.12

Best Answer

It is possible to do this yourself using AppleScript and other tools.

Requirement: System Preferences > Security & Privacy > Accessibility to be checked on for Alfred 3.

tell application "System Events" to tell process "Safari"

    with timeout of 0 seconds
        set allElements to entire contents of toolbar 1 of window 1
    end timeout

    repeat with uiElement in allElements
        if class of uiElement is button and description of uiElement is "Recent Tab List" then click uiElement
    end repeat

end tell

I use Alfred to trigger the AppleScript using a hotkey or keyword.

screen shot 2018-06-06 at 16 38 04

Here's my workflow: https://0x0.st/s_jz.zip

(I originally posted this answer on GitHub)

EDIT March 2019:

Quicker AppleScript is as follows. It works from Script Editor but I've not been able to get it to work from Alfred. YMMV.

tell application "System Events"
    tell process "Safari"
        set extVar to "Recent Tab List"

        tell first UI element of last group of last toolbar of first window
            click (first button where its description = extVar)
        end tell
    end tell
end tell