How to enable "Allow Remote Automation" in Safari programmatically

Viewed 5068

I am using macOS Sierra 10.12.4 with safari version 10.1

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

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"

Any idea which plist contains that info?

2 Answers

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

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

Hope this helps..

Related