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

Use AppleScript to start Internet Sharing at startup System
I have always been bothered that the Internet Sharing option must be started manually every time I restart the computer at home. I have seen other solutions for fixing this, but none that didn't require the terminal. Then I thought about trying it out with AppleScript's new UI access (download link, requires Developer Tools). It works great! Here is the text of the script (an adaptation of a sample script posted on Apple's website):
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 10
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
end tell
end tell
end tell

ignoring application responses
tell application "System Preferences" to quit
end ignoring
Just cut and paste it into Script Editor and save it as an application. Then just make it a login item.

[Editor's note: I haven't tested this myself, but it seems much simpler than the previously posted hint. There's also another hint that may be useful...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[20,845 views]  

Use AppleScript to start Internet Sharing at startup | 18 comments | Create New Account
Click here to return to the 'Use AppleScript to start Internet Sharing at startup' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Do not work for me
Authored by: eevyl on Jan 11, '03 08:21:21PM

After installing the System Events beta, the script do not work for me, giving the error:

System Events got an error: NSReceiverEvaluationScriptError: 4



[ Reply to This | # ]
Re: Do not work for me
Authored by: eevyl on Jan 11, '03 08:31:21PM

I reply to myself, forgot to activate the Universal Access thing... sorry :)



[ Reply to This | # ]
Add one thing?
Authored by: stevec on Jan 11, '03 11:01:13PM

Can one of you Applescript gurus out there tell me how to add the check box for "Share the connection with other computers on built in ethernet" to this script?

I have a dual NIC setup and without that this script is pretty much useless to me.



[ Reply to This | # ]
Add one thing?
Authored by: thefinite on Jan 11, '03 11:16:38PM
After you have checked the box once, it should stay checked. If it does not stay checked, and you need to recheck it every time you start Internet Sharing, add the following lines after "delay 1" and before "Click button start":

Click checkbox "Share the connection with other computers on Built-in Ethernet"
delay 1

If it doesn't work, shoot me an email at aaronmiller@NOSPAMmac.com and let me know what error comes up. Obviously, remove the NOSPAM from my address.

[ Reply to This | # ]
Re: Do not work for me
Authored by: carbondave on Jan 12, '03 11:43:41AM

This script is great but it is not as easy as it was made to sound. First install the UI Scripting Beta then go into the Universal Access prefs and check "Enable access for assistive devices" and move on to saving the script as an app and putting it in you Login Items. After that you are good to go.



[ Reply to This | # ]
Re: Do not work for me
Authored by: rgmichel on Feb 16, '04 10:07:16AM

OK. But what is the UI Scripting Beta? Is this on the Apple web site?
Panther did leave File sharing "on" on a reboot at first, then I did one of the security updates and it stopped remembering that file sharing should be on. So, this script would be great.

---
Bob



[ Reply to This | # ]
Re: Do not work for me
Authored by: rgmichel on Feb 16, '04 10:12:03AM

OK. I have it working. I guess the thing to do is to go into the Universal Access menu item of System preferences and enable universal access for assistive devices. Then, the script works. Brialliant. Thanks.

---
Bob



[ Reply to This | # ]
Translate the menu items to get it work.
Authored by: Anthony on Jan 12, '03 06:54:12AM

Hi,

On my french Mac OS X I had to translate the menu items , for example :

"Sharing" becomes "Partage"

But it works great ! :)



[ Reply to This | # ]
Syntax error?
Authored by: jspivack on Jan 12, '03 05:48:10PM

I cut-and-pasted the script as instructed, and when I tried to check the syntax, I got a syntax error:
"Expected end of line but got class name"
and "menu item" in line 6 was highlighted...any ideas? I'm running OS X.2.3, I've got the assistive-devices box checked in Universal Access, and I've got ScriptEditor v1.9...
thanks
Jeff



[ Reply to This | # ]
Syntax error?
Authored by: thefinite on Jan 12, '03 08:40:29PM

Did you install the System Events Beta? That part is necessary for this script to work, not just the new version of Script Editor. The link in the start of this article points to the file you would need.



[ Reply to This | # ]
Requires admin access
Authored by: splattertrousers on Jan 13, '03 12:32:54PM

As far as I can tell, starting the sharing requires administrator access. This means that this script will only work for administrator users.



[ Reply to This | # ]
Can't get script to start
Authored by: SeanAhern on Mar 17, '03 02:08:38AM

I've done everything all the comments say, and the script works fine
from within Script Editor when I hit Run.

But when I save it as an Application and start it from the Finder, I always
get this error:

Could not run the script "Start Internet Sharing" because of a program
error. -1344

Like I said, the same script, as source, works just fine inside the Script
editor.

Any ideas?

---
-Sean



[ Reply to This | # ]
Use AppleScript to start Internet Sharing at startup
Authored by: hedgepig on Mar 18, '03 05:45:36AM

In the latest versions of OS X there is a commandline script for this purpose
(don't know since when..)

just issue /usr/libexec/InternetSharing

this starts Internetsharing

should be easy to include this in a startupfile so internetsharing is started at login.



[ Reply to This | # ]
Use AppleScript to start Internet Sharing at startup
Authored by: mkosarin on Jun 04, '03 06:37:42PM

The applescript opens on login, but then i have to start the script manually each time. Is there a way to have it open *and* execute on login?



[ Reply to This | # ]
Use AppleScript to start Internet Sharing at startup
Authored by: TheHolySpirit on Dec 17, '03 06:48:46PM

Use ScriptEditor to open the Script you want to be executed on LogIn. Choose "Save As..." from "File" menu, change the "File Format" from Script to Application and save it to disk.
Now you can add that Application as a Startup Item in the System Preferences.



[ Reply to This | # ]
Use AppleScript to start Internet Sharing at startup
Authored by: robfryatt on Oct 07, '03 05:18:14AM

Cut and paste doen't work. the script don't run and i get a syntax error, highlighting the first \ in the first line. I have no experience of Apple script so my exploring stops here. I would love to sort this out if any one can help



[ Reply to This | # ]
Use AppleScript to start Internet Sharing at startup
Authored by: vman on Oct 26, '03 01:25:34PM

You have to remove any backslash before any quotation-mark...



[ Reply to This | # ]
Use AppleScript to start Internet Sharing at startup
Authored by: jeopardyracing@y on Nov 17, '03 03:02:54PM

Can you help me with a similar problem?

I HAVE to deal with Windows PCs at home, but when I go on campus to the network I want to be able to switch Windows sharing off in Panther. Just like you, I found doing this manually to be a royal pain given how often I need to do it. What would be a good Applescript to turn Windows Sharing and File Sharing on and off just as quickly. PLEASE HELP - I'm an OS X newbie and this is driving me crazy!

Thanks,

Rich



[ Reply to This | # ]