Applescript - Access to hidden processes.

Discussion in 'Mac Programming' started by eleven7, Jan 31, 2012.

  1. macrumors regular

    Joined:
    Mar 14, 2009
    Location:
    Japan
    #1
    I'm attempting to write a piece of applescript to toggle internet sharing on/off.
    The problem is I want to run the whole script hidden but the following code gives me an error because the 'Sharing' menu isn't accessible after I set the 'System Preference' process to false. Is there any other way I can get around this or do I just have to put up with sitting watching the script run the steps.

    Code:
    tell application "System Preferences"
    	activate
    end tell
    tell application "System Events"
    	set visible of process "System Preferences" to false
    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
    				delay 1
    			end if
    		end tell
    	end tell
    end tell
    
    tell application "System Preferences"
    	quit
    end tell
    
     
  2. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    If you are going to use System Events to script the user interface, then yes, you will need to show the user interface.
     

Share This Page