How to programmatically enable "Allow Remote Automation" in Safari

I am using macOS Sierra 10.12.4 with safari 10.1 version

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

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

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

      

However, I did not find an option to enable "Allow Remote Automation"

Any idea which contains this information?

+4


source to share


3 answers


Unable to toggle the parameter using the described method.



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

+1


source


This can also be done with AppleScript, if this is not possible by changing the plist. To do this, first enable development from Safari preferences, and then select "Allow Remote Automation" from the "Development" menu. Here is the AppleScript I wrote to enable Allow Remote Automation (this goes for both 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 have enabled the development menu from the safari settings only if it is unchecked.

Hope it helps.

+1


source


as answered in a less general case regarding the High Sierra fooobar.com/questions/386833 / ... ,

recommended one-line solution from Apple docs - execute

safaridriver --enable

      

It will ask for the admin password, so some people install sudo (dangerous) without a password, or do some other workaround like calling from Applescript.

I have verified that this works with Mojave and Safari 12.0.3, and have verified that it works regardless of whether the Develop menu is enabled, although you probably want to save on clicks and just enable that too:

defaults write com.apple.Safari IncludeDevelopMenu 1

      

0


source







All Articles