如何从命令行重新加载Safari扩展?

时间:2011-04-10 14:06:21

标签: applescript safari-extension

我需要从命令行“重新加载”Safari扩展(稍后再构建包)。

如何做到这一点?

为什么?

我想一步到位 - 我的代码是在CoffeeScript中,因此无论如何我都在编译它。

我尝试了什么?

除了谷歌无望地搜索我尝试使用这个AppleScript:

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

出了哪些错误:

  

系统事件出错:无法获取进程“Safari”窗口“Extension Builder”的“重新加载”按钮。

这种变化:

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

哪个不会出错,但实际上也没有做任何事情。

2 个答案:

答案 0 :(得分:5)

可能是按钮未按预期“命名”。查看UI Browser以查看应用程序的界面层次结构,以便与GUI脚本一起使用。

可以通过以下方式访问“重新加载”按钮:

click button "Reload"  of UI element "ReloadUninstall[NAME OF EXTENSION HERE]" \
  of UI element 1 of scroll area 1 of window "Extension Builder"

答案 1 :(得分:2)

自写入接受的答案以来,扩展浏览器的视图层次结构似乎已更改。这个脚本适合我:

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

请注意,需要打开Safari和Extension Builder窗口才能使其正常工作