Script to enable extension in Safari 10.X

ndeal
New Contributor III

I found some other forum posts about enabling Safari extensions programmatically but they were somewhat dated and the methods recommended haven't been working for me as of yet (it's possible I'm something wrong, though). So I'm asking if anyone has any recent experience with using a script or some other automated method to enable Safari extensions (not addins) for users? Or does anyone have recommendations of things to try? Any advice would be much appreciated.

6 REPLIES 6

clint5047
New Contributor III

Pre-Sierra you can do some of this with AppleScript GUI automation, but this broke in Sierra due to SIP protection of the TCC.db file.
I had a case open with Apple for this and currently they are not providing options for this on purpose (security considerations), but they did put a feature request in for this.

If you're looking to do this pre-Sierra, I can share some of my scripts with you if you'd like.

ndeal
New Contributor III

Thanks! We definitely have a need on the Sierra platform but I would like to see the scripts you used for previous OS revs. We do still have El Cap and Yosemite machines in our environment.

I've opened a case with Apple on this. Maybe if enough people complain they will bump up the priority of the feature request. I appreciate the info!

clint5047
New Contributor III

Here you go, edited it some to remove some of the custom stuff we do here, but it should get you in the right direction:

#!/bin/bash
extName="ublock.safariextz"
extPath="/Users/$currentUser/Library/Safari/Extensions/"
packageExtLocation="/tmp/"
tccPath="/Library/Application Support/com.apple.TCC/TCC.db"

sqlite3 "$tccPath" "INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','com.apple.Terminal',0,1,1,NULL,NULL)"          
sqlite3 "$tccPath" "INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','/usr/bin/osascript',1,1,1,NULL,NULL)"
sqlite3 "$tccPath" "INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','com.apple.loginwindow',0,1,1,NULL,NULL)"

# Give it some time to process..
sleep 1

# Now we're going to mess with UI elements. First we open the Extension, which initiates copy to ~/Library/Safari/Extensions/
# Then we're going to tell Safari to hit the Trust button, which creates the encryped keychain entry
# Then we close the Preferences Window by using Command + W.

osascript <<END
tell application "Safari" to activate
delay 1
tell application "System Events"
tell application process "Safari"
set frontmost to true
tell application "Safari" to open location "$packageExtLocation$extName"
delay 1
click button 1 of sheet 1 of window 1
keystroke "w" using command down
end tell
end tell
END

ndeal
New Contributor III

Thanks a bunch! Much appreciated.

I submitted a case to Apple and they instructed me to file a bug report/feature requests which was just closed with the rank of "no value" and a note that they have not plans to do this because of past issues with malware. Guess I won't get my hopes up for a change in the future.

bentoms
Release Candidate Programs Tester

Sorry about this... (someone at Apple reads my blog it seems)...

optional image ALT text

ndeal
New Contributor III

Why I oughta... ;)