Script to disable pop-up blocker in Safari

aaron_kelley
Contributor

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

1 ACCEPTED SOLUTION

Josh_Smith
Contributor III

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 solution in original post

3 REPLIES 3

aaron_kelley
Contributor
 

Josh_Smith
Contributor III

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

aaron_kelley
Contributor

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