How do I toggle Java on/off in Safari browser?

4

In Safari preferences there is an option to disable Java which is nice but a bit cumbersome. Is there a plugin/addon/extension or an easy way to toggle Java on/off?

Henrik Söderlund

Posted 2013-01-24T03:09:47.553

Reputation: 641

Respectfully, it's ridiculous to say that a three step process is cumbersome. You want to go out to the internet, find a program, install it, activate the program, and flip a switch, to turn off Java instead of use a built in button combination, a point and click, and another point and click? No, there's no extension because the process can't be made simpler than it already is. – Everett – 2013-01-24T04:41:10.490

@Everett - I have to disagree. If you do a task often enough, even saving a couple of clicks can be worthwhile. I used to switch network locations a lot and ended up using quicksilver to simplify it, so I know exactly why Henrik is asking. – Chris – 2013-01-24T17:05:03.173

1@Chris - Apparently I stand corrected. Also thank you for mentioning the Quicksilver thing. It works in LaunchBar too. You just made my life easier AND taught an old dog new tricks. That's pretty awesome. – Everett – 2013-01-24T19:00:50.597

@HenrikSöderlund - Thank you for your useful snark. Chris has an awesome answer. – Everett – 2013-01-24T19:02:24.293

@Everett - You're welcome! I haven't used LaunchBar and to be honest I don't even use Quicksilver much now; I mostly just use LaunchPad these days. I set a hotkey of Ctrl + L for launchpad and that does most of what I want. – Chris – 2013-01-24T19:30:41.320

Answers

3

You could use applescript to toggle Java off/on. Save the script as an application and call it with a hotkey or from a link.

The following worked for me (YMMV):

try
        tell application "Safari"
                activate
        end tell  
        tell application "System Events"
                tell process "Safari"
                        click menu item "Preferences…" of menu "Safari" of menu bar item "Safari" of menu bar 1
                        click button "Security" of tool bar 1 of window 1
                        click checkbox "Enable Java" of group 1 of group 1 of window "Security"
                        click button 1 of window "Security"
                end tell
        end tell
end try

Edit:
A link to the code:
http://pastie.org/private/ea7qbuareh6uje8zsglcia

Chris

Posted 2013-01-24T03:09:47.553

Reputation: 1 032

Excellent, I thought there would be a solution! But hey, in the AppleScript editor, it tells me "expected end of line, but found class" and selects the word "checkbox" – Henrik Söderlund – 2013-01-25T01:39:59.013

Try it now. For some reason the formatting of the code is really screwy. There was a new line missing before the "click checkbox..." line – Chris – 2013-01-25T03:22:24.927

I pasted your great solution as an "extension" in Alfred Launcher App and assigned a hotkey through there too, now works beautifully with Control+Alt+Cmd+J. Many thanks! – Henrik Söderlund – 2013-01-26T13:51:29.660

@HenrikSöderlund - You're welcome; happy to help. – Chris – 2013-01-27T03:41:51.753

2

With Safari open, hit Command, (command and comma together). When Preferences opens select Security. Uncheck the third box down that says Enable Java.enter image description here

Everett

Posted 2013-01-24T03:09:47.553

Reputation: 5 425