Quickly Toggle Sharing Preferences In OS X With An AppleScript

If you share files, printers, internet or other things from your Mac, it can get annoying constantly navigating through System Preferences turning it on and off. Here's an AppleScript that can toggle any of those settings on and off with one click.

OS X's sharing features are pretty cool, but if you leave them on all the time, you may be leaving yourself vulnerable to outside attackers. As such, you probably turn these settings on and off a lot, which can get annoying since they're buried in System Preferences. To speed up the process, paste this code into AppleScript Editor:

tell application "System Preferences" activate end tell

tell application "System Events" tell process "System Preferences" click menu item "Sharing" of menu "View" of menu bar 1 delay 2 tell window "Sharing" click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1 delay 1 if (exists sheet 1) then if (exists button "Turn AirPort On" of sheet 1) then click button "Turn AirPort On" of sheet 1 delay 1 end if click button "Start" of sheet 1 end if end tell end tell end tell

The above script toggles Internet Sharing on and off, though with a bit of tweaking you can make it work for any of the other sharing preferences. Just change row 11 in line 10 of the script to match the checkbox you want to check — for example, File Sharing is the third checkbox down, so you'd change row 11 to row 3. When you're done, just save the script as an application. Now, whenever you want to toggle that setting, just double-click on the script (or, even better, launch it with Quicksilver) to toggle that setting. It'll still open up System Preferences, but it'll do all the clicking for you, and faster than you probably did it yourself. Hit the link to read more.

Change System Preferences by Script [Macworld]


Be the first to comment on this story!

Trending Stories Right Now