Advertisement
Guest User

AppleScript for Sharing Toggle - OS X

a guest
Jan 6th, 2013
589
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tell application "System Preferences"
  2.     activate
  3. end tell
  4.  
  5. tell application "System Events"
  6.     tell process "System Preferences"
  7.         click menu item "Sharing" of menu "View" of menu bar 1
  8.         delay 2
  9.         tell window "Sharing"
  10.             if (value of checkbox 1 of row 9 of table 1 of scroll area 1 of group 1 is 1) then
  11.                 click checkbox 1 of row 9 of table 1 of scroll area 1 of group 1
  12.                 try
  13.                     set makiaeawirelessstatus to do shell script "networksetup -getairportpower en1"
  14.                 on error
  15.                     display dialog "The script did not work as intended, please check the networksetup command (in terminal) works on your system. It has been tested on mac os 10.7 (Build 11A459e). Other versions of mac os may not have this command available. Please open the applescript in applescript editor for more details." buttons {"kthxbai"}
  16.                 end try
  17.                 if makiaeawirelessstatus is "Wi-Fi Power (en1): On" then
  18.                     do shell script "networksetup -setairportpower en1 off"
  19.                 else
  20.                     display dialog "The script did not work as intended, please check the networksetup command (in terminal) works on your system. It has been tested on mac os 10.7 (Build 11A459e). Other versions of mac os may not have this command available. Please open the applescript in applescript editor for more details." buttons {"kthxbai"}
  21.                 end if
  22.             else
  23.                 click checkbox 1 of row 9 of table 1 of scroll area 1 of group 1
  24.                 delay 1
  25.                 if (exists sheet 1) then
  26.                     if (exists button "Turn Wi-FI On" of sheet 1) then
  27.                         click button "Turn Wi-Fi On" of sheet 1
  28.                         delay 1
  29.                     end if
  30.                     click button "Start" of sheet 1
  31.                 end if
  32.             end if
  33.         end tell
  34.     end tell
  35.     delay 2
  36. end tell
  37.  
  38. if application "System Preferences" is running then
  39.     tell application "System Preferences" to quit
  40. end if
Advertisement
RAW Paste Data Copied
Advertisement