macOS Sierra - how to enable “Allow Remote Automation” using command line

China☆狼群 提交于 2019-12-03 04:45:58
Montmons

Hmm ok, so as per my comment:

You could do defaults write com.apple.Safari IncludeDevelopMenu YES to activate the development menu via terminal. You could get python to execute this command for you using the subprocess module.

According to this this question it seems that one used to be able to simply do defaults write com.apple.Safari AllowRemoteAutomation 1. However, since Safari 10 this option has apparently been subjected to a higher security protocol or something (maybe because of the System Integrity Protection that was introduced). I've been looking for the plistfile that now holds the setting, but I have not been able to find it. Maybe it's not even there in an actual plistfile anymore.

I guess this leaves you with 2 options:

  1. Use apple's osascript to simulate the needed mouseclicks.
  2. Repost your question on AskDifferent or Apple's own developers forum, since you are more likely to find someone with in-depth knowledge of macOS.

I found the answer from: https://developer.apple.com/documentation/webkit/testing_with_webdriver_in_safari

safaridriver --enable

It will prompt for an admin password, so some people setup passwordless sudo (dangerous) or do another workaround like calling from an Applescript

I tested that this works with Mojave and Safari 12.0.3 and verified that it works regardless of if the Develop menu is enabled, though you probably want to save yourself the clicks and just enable that too:

defaults write com.apple.Safari IncludeDevelopMenu 1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!