我正在使用macOS Sierra 10.12.4和safari 10.1版
我需要以编程方式在Safari中的“开发”选项卡中启用“允许远程自动化”选项。
我可以运行下面的命令来更改〜/ Library / Preferences中的com.apple.Safari.plist文件,它可以完美地启用Develop菜单。
`defaults write com.apple.Safari IncludeDevelopMenu -bool true`
但是,我没有找到任何选项来启用“允许远程自动化”
任何plist包含该信息的想法?
无法使用您描述的方法切换设置。
从Safari 11开始,您可以使用--enable命令行选项强制safaridriver进行身份验证。验证后,将设置此菜单项。这还将缓存您的其余登录会话的身份验证。随后的safaridriver调用(例如,Selenium库)将不需要进一步设置。
如果通过修改plist无法实现,也可以使用AppleScript完成。为此,首先从Safari首选项启用开发,然后从“开发”菜单中选择“允许远程自动化”。以下是我编写的AppleScript以启用允许远程自动化(这包括上述两个步骤)。
tell application "Safari" to activate
delay 2
tell application "System Events"
tell application process "Safari"
keystroke "," using command down
set frontmost to true
tell window 1
click button "Advanced" of toolbar 1
delay 2
set theCheckbox to checkbox 4 of group 1 of group 1 of it
tell theCheckbox
if not (its value as boolean) then click theCheckbox
end tell
delay 2
keystroke "w" using command down
delay 2
end tell
tell menu bar item "Develop" of menu bar 1
click
delay 2
click menu item "Allow Remote Automation" of menu 1
delay 2
end tell
end tell
end tell
tell application "Safari" to quit
注意:这里我只在取消选中时才从safari首选项中启用开发菜单。
希望这可以帮助..