Modifying Safari's Auto-Play Preferences
I saw an interesting question today on the MacAdmins Slack regarding setting the Auto-Play preferences introduced in 10.13's Safari.
Curiosity took hold.
After a quick look through I saw this sqlite3 database:
~/Library/Safari/PerSitePreferences.db
I noticed that after every modification to the domain based Auto-Play preference, this file would change. Opening it up in sqlite browser, I saw some positive results from my curiosity.
I played around with some settings and took note of what the values translated to in this database.
Column Name | Column Value Type | Possible Values
--|---|--
domain
| TEXT | url of site to be configured
preference
| TEXT | So far, only PerSitePreferencesAutoplay
. Possible for more values later
preference_value
| NUMBER | 0 = "Allow All Auto-Play" , 1 = "Stop Media with Sound", 2 = "Never Auto-play".
After digging some more, I found one could write to this DB and have the changes as long as Safari was not open. Here is the script I used to test it.
#!/bin/bash
loggedInUser="$(/usr/bin/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 + "\n");')"
urlToModify="munki.bsd7.org"
# Value to Set
# 0 = "Allow All Auto-Play" , 1 = "Stop Media with Sound", 2 = "Never Auto-play"
valueToSet=0
current="$(/usr/bin/sqlite3 "/Users/$loggedInUser/Library/Safari/PerSitePreferences.db" "SELECT EXISTS(SELECT preference_value FROM preference_values WHERE domain='$urlToModify');")"
if [ "$current" == 0 ]; then
/usr/bin/sqlite3 "/Users/$loggedInUser/Library/Safari/PerSitePreferences.db" "INSERT INTO preference_values (domain, preference, preference_value) VALUES ('$urlToModify', 'PerSitePreferencesAutoplay', $valueToSet);"
echo "Domain not found in db, setting"
else
/usr/bin/sqlite3 "/Users/$loggedInUser/Library/Safari/PerSitePreferences.db" "Update preference_values SET preference_value=$valueToSet WHERE domain='$urlToModify';"
echo "Value Updated to Match"
fi
Hopefully this helps anyone who needs this and hopefully this gets turned into a configuration profile setting. psst file your radars for this! My radar for this is: 39192330