PDA

View Full Version : Applescript - Access to hidden processes.




eleven7
Jan 31, 2012, 06:22 AM
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.


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



Red Menace
Jan 31, 2012, 09:37 AM
If you are going to use System Events to script the user interface, then yes, you will need to show the user interface.