问题
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.
回答1:
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"
回答2:
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
来源:https://stackoverflow.com/questions/5612277/how-to-reload-a-safari-extension-from-the-command-line