How to reload a Safari Extension from the command

2019-05-04 07:17发布

I need to "Reload" a Safari extension from the command line (and also build the package later).

How can this be done?

Why?

I'd like to build in one step - my code is in CoffeeScript and thus I'm compiling it anyway.

What have I tried?

Apart from googling hopelessly I tried using this AppleScript:

tell application "System Events"
   tell process "Safari"
       click the button "Reload" of window "Extension Builder"
   end tell
end tell

Which errors out with:

System Events got an error: Can’t get button "Reload" of window "Extension Builder" of process "Safari".

And this variation:

tell application "System Events"
    tell process "Safari"
       tell button "Reload" of window "Extension Builder" to perform action
    end tell
end tell

Which doesn't give an error but also doesn't actually do anything.

2条回答
倾城 Initia
2楼-- · 2019-05-04 08:03

It may be that the button isn't "named" as you expect. Check out UI Browser in order to view an application's interface hierarchy for use with GUI scripting.

The "Reload" button is accessible with:

click button "Reload"  of UI element "ReloadUninstall[NAME OF EXTENSION HERE]" \
  of UI element 1 of scroll area 1 of window "Extension Builder"
查看更多
不美不萌又怎样
3楼-- · 2019-05-04 08:19

Extension Browser's view hierarchy seems to have changed since the accepted answer was written. This script works for me:

tell application "System Events"
    tell process "Safari"
         click button "Reload" of UI element 0 of window "Extension Builder"
    end tell
end tell

Note that Safari and the Extension Builder window need to be open for this to work

查看更多
登录 后发表回答