Automatically start Internet Sharing via LaunchDaemon

Nov 11, '09 07:30:00AM

Contributed by: alexclst

In the past, people have submitted hints on how to get their Macs to start internet sharing automatically at boot. All of them are either editing files in hidden directories or creating a StartupItem to do the task. Most people may not want to edit files that are for the system, and Leopard and later versions of OS X use LaunchDaemons, not StartupItems to run scripts or executables at boot.

I created a LaunchDaemon plist based on the composition of the iStat Server's LaunchDaemon plist to run the InternetSharing executable automatically at boot. Here's what it looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Disabled</key>
	<false/>
	<key>GroupName</key>
	<string>wheel</string>
	<key>UserName</key>
	<string>root</string>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>InternetSharing</string>
	<key>OnDemand</key>
	<false/>
	<key>Program</key>
	<string>/usr/libexec/InternetSharing</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StartOnMount</key>
	<false/>
</dict>
</plist>
Save the above as net.tenseg.autointernetsharing.plist; alternatively, you can download the plist file (4KB) from my web site.

To install it, just copy the plist file into /Library/LaunchDaemons. The next time you reboot, the Internet Sharing option should already be turned on (once you're fully logged into a user account). The end result is identical to the older hints, but uses the new LaunchDaemon implementation rather than editing system files or installing a StartupItem.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2009110114123254