Allow JavaScript from Apple Events in Safari through Terminal Mac

放肆的年华 提交于 2019-12-12 08:25:00

问题


I'm writing a program that executes do javascript in Safari. The only problem is that I'm trying to make the app give its self permission to do it. I'm trying to locate the file that handles the Safari developer preferences so that I can do this. Does anyone have any idea where this might be or how to change these settings?


回答1:


It's in Safari's preferences plist at ~/Library/Preferences/com.apple.Safari.plist. The key you want is AllowJavaScriptFromAppleEvents. You can set it using defaults:

#to turn it on
defaults write -app Safari AllowJavaScriptFromAppleEvents 1
#to turn it off
defaults write -app Safari AllowJavaScriptFromAppleEvents 0



回答2:


The virtual keyboard thing did not work for me. As StarPlayr at apple's develepoer forum has found out the problem is in something else. For me problem occurred when i tried to do that on remote mac. For some people plugging in a keyboard and mouse to the Server allowed to turn on JavaScript Apple Events in Safari and set the password.

However, for me that wasn't an option, so the next best thing is use an accessbility scripting feature and have the machine think a user is doing the clicks, allowing you to set the password:

-- The delays can be shorter, coordinates may vary

-- Best way to get the coordinates is with Apple screen capture (command-shift-3) from upper right to lower left (the coordinates will be shown)

-- if one spends the time, the click events can be converted to Accessibility AppleScript objects by capturing them as variables, or checking the events and using the events instead of the click coordinates

tell application "System Events"


  tell application "Safari"

       activate

  end tell


  delay 1

-- click develop menu (make sure its on first)

  click at {430, 12}


  delay 1


-- click Allow Javascript menu from Apple Events

  click at {615, 615}


  delay 1


-- Click the Allow Button

  click at {1010, 386}

end tell


来源:https://stackoverflow.com/questions/37802673/allow-javascript-from-apple-events-in-safari-through-terminal-mac

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