OSX and Public Wifi – Toggle settings with AppleScript

I like to remind folks when moving their Apple laptop to public wifi that they need to remember to turn off the iLife application sharing such as iTunes and iPhoto. Then turn on their firewall.

So here is an AppleScript that will do just that. It is written and tested on OSX Lion with iLife 11. So you may have to play with it for your version if that is not what you are running.  Keep in mind it is a toggle script.  It will reverse the settings of iPhoto, iTunes sharing and the firewall. So it is assumed you share both with the firewall off when at home.

Also you need to ensure Enable access for assistive devices is checked under Universal Access in System Preference.

Just cut and paste the below script into the AppleScript editor.  Then save either as an application on your desktop you can double click. Or save as an AppleScript where an application like LaunchBar can use it as an action. ~/Library/Application Support/LaunchBar/Actions

— This script is setup for OSX Lion with iLife 11

— You may have to edit menu item, bar and button numbers to adapt for other versions with altered gui.

— Technically this script will toggle the states from whatever they were when you run it.

— So pay attention to if you are setting things to be secure before getting onto public wifi

 

tell application “iTunes” to activate

 

tell application “System Events”

tell process “iTunes”

click menu item 3 of menu “iTunes” of menu bar 1

click button “Sharing” of tool bar 1 of window 1

click checkbox “Share my library on my local network” of group 1 of window 1

click button “Ok” of window 1

end tell

end tell

 

tell application “iPhoto” to activate

 

tell application “System Events”

tell process “iPhoto”

click menu item 3 of menu “iPhoto” of menu bar 1

click button “Sharing” of tool bar 1 of window 1

click checkbox “Share my photos” of group 1 of group 1 of window 1

click button 1 of window 1

end tell

end tell

 

— This assumes you have used the firewall before and allowed the applications you want with it running.

— It will prompt you to enter your admin credentials in order to turn the firewall on

tell application “System Preferences”

activate

tell application “System Events”

tell process “System Preferences”

click menu item “Show All Preferences” of menu 1 of menu bar item “View” of menu bar 1

click button 6 of scroll area 1 of window “System Preferences”

click button 4 of window “Security & Privacy”

click button “Start” of tab group 1 of window “Security & Privacy”

end tell

end tell

delay 3

quit

end tell


Share

2 Replies to “OSX and Public Wifi – Toggle settings with AppleScript”

  1. Stupid question sir. What is the purpose of turning on sharing in ilife and then the firewall? I’m listening to your visit on Mac Power Users. All good stuff.

    brian g
    toronto

Comments are closed.