Okay, so at home I use a wireless network, but at work I use a wired one. When at work, I share my wired connection over Airport to my iPhone. This works fine except that I mist manually turn it on and off. I also use the excellent DSW (Do Something When) tool, so I thought it would be good to have DSW start Internet Sharing automagically whenever my work USB drive is connected. I found the script below on this site:
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 3
tell window "Sharing"
if (exists tab group 1) then
tell tab group 1
click radio button "Internet"
delay 1
click button "Start"
delay 1
end tell
end if
if exists sheet 1 then
tell sheet 1
click button "Start"
end tell
end if
end tell
end tell
end tell
ignoring application responses
tell application "System Preferences" to quit
end ignoring
For some reason, though, if I paste it in, compile it, and then hit run, it gets me as far as the Sharing screen, but it fails to put a check mark in the "Internet Sharing" item and further never clicks the Start button (since the Internet Sharing item is never clicked, the Start button never shows).
I noticed the one line says:
"click radio button "Internet"
and I've tried modifying it to say "Internet Sharing" instead, but I get the same results. Anyone know why this isn't working?
Further, Leopard seems to remember the Internet Sharing state, so I'm curious how I would automate this to also disable Internet Sharing (I know I can have DSW do it when my work drive in unmounted... I just need the AppleScript). Any thoughts?
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 3
tell window "Sharing"
if (exists tab group 1) then
tell tab group 1
click radio button "Internet"
delay 1
click button "Start"
delay 1
end tell
end if
if exists sheet 1 then
tell sheet 1
click button "Start"
end tell
end if
end tell
end tell
end tell
ignoring application responses
tell application "System Preferences" to quit
end ignoring
For some reason, though, if I paste it in, compile it, and then hit run, it gets me as far as the Sharing screen, but it fails to put a check mark in the "Internet Sharing" item and further never clicks the Start button (since the Internet Sharing item is never clicked, the Start button never shows).
I noticed the one line says:
"click radio button "Internet"
and I've tried modifying it to say "Internet Sharing" instead, but I get the same results. Anyone know why this isn't working?
Further, Leopard seems to remember the Internet Sharing state, so I'm curious how I would automate this to also disable Internet Sharing (I know I can have DSW do it when my work drive in unmounted... I just need the AppleScript). Any thoughts?