Assign keyboard shortcut to Safari Extensions?

Solution 1:

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