我为自己编写了一个 Safari 扩展,但我不是苹果开发人员,所以每次我关闭 safari 时,它都会删除我的扩展,我必须进入设置再次打开“允许未签名的扩展”。
因此,我决定编写一个 mac 脚本来一次性完成所有这些工作。我可以让它点击进入 Safari 的开发者菜单,但我就是不知道如何让它点击复选框。
我编写了这段代码,直到最后几行我尝试单击复选框:
tell application "System Events"
tell process "Safari"
set frontmost to true
delay 1
click menu item "Settings…" of menu "Safari" of menu bar 1
delay 1
click button "Developer" of toolbar 1 of window 1
delay 1
end tell
tell process "Safari"
tell window "Developer"
click checkbox "Allow unsigned extensions"
end tell
end tell
end tell
它返回此错误消息:
系统事件出现错误:无法获取进程“Safari”的窗口“Developer”的复选框“允许未签名的扩展”。
就像我能够访问 Safari 菜单的这部分,但我就是不知道如何让它单击“允许未签名的扩展”复选框。
您可以在 Safari 菜单中触发开发者设置,然后单击复选框。然后,它会要求您通过 Touch ID 或密码进行身份验证来确认这一点。 下面的示例在 Sonoma 14.5 上进行了测试。
tell application "System Events" to tell process "Safari"
set frontmost to true
try
click (first menu item of menu 1 of menu bar item "Develop" of menu bar 1 whose title starts with "Developer Settings")
end try
click checkbox "Allow unsigned extensions" of group 1 of group 1 of front window
end tell