如何启用“允许远程自动化"在 Safari 中以编程方式 [英] How to enable "Allow Remote Automation" in Safari programmatically

查看:149
本文介绍了如何启用“允许远程自动化"在 Safari 中以编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 macOS Sierra 10.12.4 和 Safari 版本 10.1

I am using macOS Sierra 10.12.4 with safari version 10.1

我需要以编程方式在 Safari 的开发"选项卡中启用允许远程自动化"选项.

I need to enable the Allow Remote Automation option in Develop tab in Safari programmatically.

我可以运行以下命令来更改 ~/Library/Preferences 中的 com.apple.Safari.plist 文件,从而完美启用开发"菜单.

I can run the below command which changes the com.apple.Safari.plist file in the ~/Library/Preferences and that enables the Develop menu perfectly.

`defaults write com.apple.Safari IncludeDevelopMenu -bool true` 

但是我没有找到任何启​​用允许远程自动化"的选项

However I did not find any option to enable the "Allow Remote Automation"

知道哪个 plist 包含该信息吗?

Any idea which plist contains that info?

推荐答案

如果通过修改 plist 无法实现,也可以使用 AppleScript 来完成.为此,首先从 Safari 首选项启用开发,然后从开发"菜单中选择允许远程自动化".这是我为启用允许远程自动化而编写的 AppleScript(包括上述两个步骤).

It can also be done using AppleScript if it is not possible by modifying the plist. To do that, first enable develop from Safari preferences and then choose Allow Remote Automation from the Develop menu. Here is the AppleScript that I wrote to enable Allow Remote Automation (this covers both the steps mentioned above).

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 首选项启用开发菜单.

Note: Here I enabled develop menu from safari preferences only if it is unchecked.

希望这有帮助..

这篇关于如何启用“允许远程自动化"在 Safari 中以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆