Automatically enable the Java web plug-ins setting in Safari 6.0.3 and later
One of the features of Apple’s Safari 6.0.3 update is that it turns off the automatic execution of Java applets through Safari, even if the Java browser plug-in is otherwise enabled.
Safari 6.0.3 does allow for the automatic execution of Java applets to be re-enabled through the browser. However, if it’s been a while since a Java applet was launched, then automatic execution of Java applets is once again automatically disabled.
This was going to be an issue at my workplace, as we have a couple of applications that rely on Java applets running through the browser. Fortunately, I already had a fix for this issue; it just needed to be updated with some additional commands.
To make this work, I’ve written a script and launch agent combination. The script will perform a couple of tasks:
1. Set the com.apple.WebKit.JavaPlugInLastUsedTimestamp plist key in ~/Library/Preferences/.GlobalPreferences.plist
2. Enable the Enable applet plug-in and Web Start Applications setting in the Java Preferences application.
#!/bin/sh # DYNAMICALLY SET THE UUID FOR THE BYHOST FILE NAMING if [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` == "00000000-0000-1000-8000-" ]]; then MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c51-62 | awk {'print tolower()'}` elif [[ `ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-50` != "00000000-0000-1000-8000-" ]]; then MAC_UUID=`ioreg -rd1 -c IOPlatformExpertDevice | grep -i "UUID" | cut -c27-62` fi # Enable Java browser plug-ins in Safari 6.0.3 and later # for the current user by setting the com.apple.WebKit.JavaPlugInLastUsedTimestamp # key in ~/Library/Preferences/.GlobalPreferences.plist /usr/libexec/PlistBuddy -c "Delete :com.apple.WebKit.JavaPlugInLastUsedTimestamp" $HOME/Library/Preferences/.GlobalPreferences.plist /usr/libexec/PlistBuddy -c "Add :com.apple.WebKit.JavaPlugInLastUsedTimestamp real $(( $(date "+%s") - 978307200 ))" $HOME/Library/Preferences/.GlobalPreferences.plist /usr/bin/plutil -convert xml1 $HOME/Library/Preferences/.GlobalPreferences.plist # Set the the "Enable applet plug-in and Web Start Applications" setting in # the Java Preferences for the current user. /usr/libexec/PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsEnabled" $HOME/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist /usr/libexec/PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsEnabled bool true" $HOME/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist /usr/libexec/PlistBuddy -c "Delete :GeneralByTask:Any:WebComponentsLastUsed" $HOME/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist /usr/libexec/PlistBuddy -c "Add :GeneralByTask:Any:WebComponentsLastUsed real $(( $(date "+%s") - 978307200 ))" $HOME/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist /usr/bin/plutil -convert xml1 $HOME/Library/Preferences/ByHost/com.apple.java.JavaPreferences.${MAC_UUID}.plist # Forces preferences to be re-read /usr/bin/killall cfprefsd
The LaunchAgent runs the script on login to any user account with the logging-in user’s privileges and permissions.
You can find the updated script here on my GitHub repo:
Outstanding. Thank you very much.
Great effort here, but it didn’t seem to work for me. I’m trying to launch a jnlp from Safari. Followed the readme. Any suggestions? Thanks either way.
Jeffery,
Your issue may be related to the second note on this Apple KBase article:
http://support.apple.com/kb/HT5672
“CoreTypes
Available for: OS X Lion v10.7 to v10.7.5, OS X Lion Server v10.7 to v10.7.5, OS X Mountain Lion v10.8 to v10.8.2
Impact: Visiting a maliciously crafted website could allow a Java Web Start application to be launched automatically even if the Java plug-in is disabled
Description: Java Web Start applications would run even if the Java plug-in was disabled. This issue was addressed by removing JNLP files from the CoreTypes safe file type list, so the Web Start application will not be run unless the user opens it in the Downloads directory.
CVE-ID
CVE-2013-0967”
Thank you for the response. I take it a “user” cannot add this file type to the “safe file” list? Keep up the good coding.
Best regards,
j
Thanks for the heads up! I hadn’t even heard about the Java change until you mentioned it!! What tipped your hand, any particular resource I can additionally throw into my feeds?
Thanks Rich – it seems to me the way to get the timer to reset to the current date is to click on the “Inactive plug-in” text, which seems to trigger loading the plugin. The text will also show if the com.apple.WebKit.JavaPlugInLastUsedTimestamp key isn’t present at all.
I suspect this is used to apply the same expiry system to the Java 7 web plugin, whereas the previous mechanism targeted Apple’s Java. On a machine with no Apple Java but with only Oracle Java installed, the old com.apple.java.JavaPreferences ByHost domain isn’t modified when I first load the plugin.
It worked like a charm! Thank you!
Does it work for Java 7 also? or just for Apple’s Java 6.
Thanks!
Kyle,
This applies to both Java 7 and Java 6.
Thanks rtrouton. Then I may be doing something wrong, because I have Java 7 and it does not work on my Safari 6.0.3.
Question: how is this key (“com.apple.WebKit.JavaPlugInLastUsedTimestamp”) updated?
As I understand it, once the 30 days are up, you will no longer be able to launch Java applets in a web browser. Is this key updated when you launch a Java applet or do you have to enable it manually (or with this script).
A small thing I do not understand: your script produces a time stamp in the form of “386671648” but when I update the time stamp from Oracles webpage (http://www.java.com/en/download/testjava.jsp) it becomes “386606982.494483”. It doesn’t appear to impact how it works, but it feels a bit weird.
Thank you for the script, though!
Reblogged this on Java Reblog.
why do you delete the key and readd it? can’t you just set it?
Is it still useful with Yosemite and Java 8 ?