Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pickaxe

macrumors 6502a
Original poster
Nov 29, 2012
760
284
Some of the apps I regularly use require root access, otherwise I'd be typing my password repeatedly. (for example, TunlrSwitcher would otherwise pop up a password prompt every time I try to change the DNS)

So I run these apps as root via terminal, but the sudo command obviously requires a password. This is a problem because I want these apps to run on boot without having to manually type in my password to launch them. Is there some way to do this? Windows has a few workarounds IIRC.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,557
6,058
sudo crontab? It's what I would use on Linux, and I think it'll work on OS X, but I don't know if that's a solution that Apple would recommend.
 

ElectricSheep

macrumors 6502
Feb 18, 2004
498
4
Wilmington, DE
The recommended way of doing this is via launchd. You create a reverse-domain named .plist file following the specifications laid out in the launchd.plist man page. For example, I like to have my IRC bouncer to be running after booting my laptop without having to remember to login and start it. I created a file called com.electricsheep.znc.plist with the following contents:

Code:
<?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>Label</key>
                <string>com.electricsheep.znc</string>
                <key>ProgramArguments</key>
                <array>
                        <string>/usr/local/bin/znc</string>
                        <string>-f</string>
                        <string>-r</string>
                        <string>--datadir=/Users/esheep/.znc/</string>
                </array>
                <key>KeepAlive</key>
                <true/>
                <key>UserName</key>
                <string>esheep</string>
        </dict>
</plist>

The plist file was dropped into /Library/LaunchDaemons. From there, the system's launchd instance manages starting znc automatically, and making sure that its still running even if it exits abnormally.

The man page for launchd.plist outlines the options available for configuring launch agents and daemons.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.