Skip to main content
Solved

Script to disable pop-up blocker in Safari


Forum|alt.badge.img+7

OK, so I commented on an old thread but do not want to take that thread up anymore.
So this user created a command to disable pop-up blocker in Safari. However, it is not working for me, so I decided to test an older version which is...
"defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaScriptCanOpenWindowsAutomatically 1"
1 meaning disabled, 0 meaning enabled. This works great. However, I can't get it to work in JSS as a script running through a policy.

I need to know how to apply this to a user-based level. I know JSS uses $3 to indicate the currently logged in user, but i'm unsure how to indicate this in the script so the command will apply to the currently logged in user and not globally. Any ideas?

Side note: it would really be better if I could have the script to write only if the file in plist is set to 0, but if at 1 make no change.

Best answer by Josh_Smith

Here is a recent presentation from the PSU MacAdmins Conference about the topic that may be helpful: https://www.youtube.com/watch?v=WgRLKbxOF2Q

If you want to enforce this setting the most reliable option would be to use a Configuration Profile.

If you want to set the preference and allow the user to change it you could have a Launch Agent run the script as the user or have the JSS run the script as root and modify the user's plist.

Example of having the JSS run the script by running the defaults command as the currently logged in user to modify that user's plist:

#!/bin/sh
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
sudo -u $loggedInUser defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2UsesPageCache 1
View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+14
  • Contributor
  • 270 replies
  • Answer
  • November 17, 2016

Here is a recent presentation from the PSU MacAdmins Conference about the topic that may be helpful: https://www.youtube.com/watch?v=WgRLKbxOF2Q

If you want to enforce this setting the most reliable option would be to use a Configuration Profile.

If you want to set the preference and allow the user to change it you could have a Launch Agent run the script as the user or have the JSS run the script as root and modify the user's plist.

Example of having the JSS run the script by running the defaults command as the currently logged in user to modify that user's plist:

#!/bin/sh
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`
sudo -u $loggedInUser defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2UsesPageCache 1

Forum|alt.badge.img+7
  • Author
  • Contributor
  • 31 replies
  • November 17, 2016

@John.Smith Thank you! That user line worked. I've probably been spending too much time with this, but I HAD to get it figured out, even if I wind up not deploying it.
Thanks again.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings