4

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
asinha
  • 337
  • 1
  • 6
  • 24

2 Answers2

1

It is not possible to toggle the setting using the method you described.

Starting in Safari 11, you can force safaridriver to authenticate by using the --enable command line option. After authenticating, this menu item will be set. This will also cache the authentication for the rest of your login session. Subsequent invocations of safaridriver (say, by the Selenium libraries) will not need further setup.

Brian Burg
  • 795
  • 4
  • 10
  • So is the correct command `sudo defaults write com.apple.Safari IncludeDevelopMenu -enable true` ? – Sam Oct 03 '17 at 13:14
  • Sorry, jumped the gun. It's `/usr/bin/safaridriver --enable`, I believe? – Sam Oct 03 '17 at 13:26
1

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..

  • I like the Applescript angle on this- it had been a "I know this is possible" but to see it in 15ish lines was instructive. one note, that this requires a manual intervention with admin password to give the app permissions. – Rian Sanderson Apr 02 '19 at 22:52