Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Toggle internet connection sharing with an Applescript System
After looking at RickoKid's last hint about toggling web proxy settings I had a think about creating an applescript using the Apple GUI plugin that would switch on Internet Connection Sharing over my second ethernet card and Airport. This is what i've come up with. It's simple and can easily be modified with some error checking routines and other bit 'n peices but i'm too lazy to do that.
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"
      tell tab group 1
        click radio button "Internet"
        delay 2
        click button "Start"
        delay 2
      end tell
    end tell
  end tell
end tell

ignoring application responses
  tell application "System Preferences" to quit
end ignoring
Just save it as an Application in ScriptEditorm, and pop it into your Login Items in System Prefs. To get UI scripts to function, you must turn on an option in System Preferences. Open System Preferences and click Universal Access. Click Seeing, then select "Enable access for assistive devices;" otherwise the plugin can't work.

This script is way easier than doing it the hard way, but it'll only work after logging in ... but maybe someone can write a small command line script to run it from a cron job or something? Hope it saves a few clicks for someone out there and thanks to RickoKid for the inspiration!
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[9,491 views]  

Toggle internet connection sharing with an Applescript | 9 comments | Create New Account
Click here to return to the 'Toggle internet connection sharing with an Applescript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle internet connection sharing with an Applescript
Authored by: CorningMUG on Oct 22, '03 11:24:58AM

This is exactly what I was looking for! For some reason when I reboot my server, the Internet sharing check box is always off.
Now how do I execute this? Place script in start up items?

---
President
Corning Macintosh Users Group
http://www.corningmug.org



[ Reply to This | # ]
Toggle internet connection sharing with an Applescript
Authored by: CorningMUG on Oct 22, '03 11:43:40AM

Actually, What I really want to do is to have a script tell Sharing to check the box to share connection with other computers on Built-in Ethernet.

---
President
Corning Macintosh Users Group
http://www.corningmug.org



[ Reply to This | # ]
InternetSharing during Startup (Was: Toggle internet connection sharing with an Applescript)
Authored by: kmschindler on Oct 22, '03 12:27:49PM
If you do not mind the command line, unix commands and so on, I described a solution to your problem in a comment on this post.

It is way down. Search for "schindler".

A further refinement using diff and patch was explained in this comment on my posting.

It is still working on 10.2.8.

[ Reply to This | # ]

Already done and will no longer be needed
Authored by: thefinite on Oct 22, '03 02:10:58PM
I have it on good authority that Panther remembers Internet Sharing after restarts. Also, you could have saved yourself the trouble of figuring out this script by searching past hints. You would have found this: link. Still, I love to see people using AppleScript.

---
--Boom Shanka

[ Reply to This | # ]

how would you GUI script mail.app?
Authored by: dhdosxid on Oct 22, '03 05:12:15PM

This GUI scripting is new to me. I can't seem to change the value of the Incoming Mail Server text field of the accounts window of the preferences menu of the mail menuitem of menu bar 1.

Any suggestions?



[ Reply to This | # ]
how would you GUI script mail.app?
Authored by: RickoKid on Oct 22, '03 06:19:11PM
You can only specify an element by name if it has a Title element. Most of the elements don't seem to be named .. so you have to specify it by it's index, for example:
text field 2 of window "foo"
Unfortunately, the UI Element Inspector doesn't tell you the index of an element - so I usually just use trial and error. You might expect that the elements would be indexed from the top of the window downwards - but apparently it seems to be all over the place (I suspect it has something to do with the order the developer adds the elements when they design the application). Anyway - in your example the "Incoming Mail server:" text field should probably be text field 4 - but that is actually the "Description:" field! Incoming Mail is the 1st text field:
text field 1 of tab group 1 of sheet 1 of window "Accounts"

---


RickoKid

[ Reply to This | # ]

how would you GUI script mail.app?
Authored by: RickoKid on Oct 23, '03 04:15:01PM
Also - I've been thinking about your problem you were trying to solve with Mail - but I was thinking it'd be easier just to script it directly - Mail after all is a scriptable application and you could probably do whatever you wanted to using it's scripting abilities. For example, if you want to change the POP server:

tell application "Mail"
	set server name of pop account "Email account" to "pop.isp.com"
end tell
That's a bit easier isn't it!!

---


RickoKid

[ Reply to This | # ]

obsolete
Authored by: Hes Nikke on Oct 23, '03 01:45:52AM
just an FYI: with Panther, this hint will be obsolete.

Panther keeps the setting when you shut down and/or reboot your computer.

---
vacuums do not suck. they merely provide an absence that allows other objects to take the place of what becomes absent.

[ Reply to This | # ]

obsolete
Authored by: dave@mmu on Oct 23, '03 03:44:46AM

Excellent news, but for now it's either this or the more complex unix type solution (which works great and i've had it working for ages now but i was just thinking of a quicker way..) Until tomorrow anyway!
Dave

---
Dave L



[ Reply to This | # ]