[launchd-dev] fork & exit in Shell Script (Revisited)
DarwinsKernel at gmail.com
Fri Nov 14 13:23:54 PST 2008
On Nov 13, 2008, at 1:00 PM, Quinn wrote:
> At 8:28 -0500 11/11/08, Charles Darwin wrote:
>> "In Mac OS X v10.4, launchd was added. This is the preferred means
>> of adding background agents on a per-user basis. "
>> that I found here:
> That's probably true, but there are certain advantages to using a
> login item, namely that a login item doesn't have to be code: it
> can be anything that the Finder can open. You can solve this
> probably with no code by simply creating an alias to the server
> volume in question and adding that alias to the login item list.
I have 10 machines here so that is practically impossible to do.
> And it turns out that mounting AFP volumes from a shell script is
> tricky. If you want the volume to act like it's been mounted via
> standard means, you can't just use mount_afp
Then what is the purpose of having that (mount_afp utility that is)
installed on your system?
> -- you have to make sure that Disk Arbitration knows about the
> volume, and that means mounting it using higher level software.
> Mounting a server volume programmatically is best done using
I will look into that. Thanks for the hint.
> * * *
> Still, if you want a launchd agent that runs when the user logs in,
> does its job, then quits and isn't relaunched for that session
I don't care if it relaunches for that session (which in my script it
doesn't by the way) what I can't get launchd to is to relaunch it
when user logs out and then logs back without rebooting the system.
> , it's pretty easy to construct one.
> $ ls -l MyScript.sh
> -rwxr-xr-x 1 quinn staff 63 Nov 13 17:44 MyScript.sh
> $ cat MyScript.sh
> #! /bin/sh
> echo "MyScript start"
> sleep 10
> echo "MyScript end"
> $ cat Library/LaunchAgents/com.apple.dts.MyScript.plist
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
> <plist version="1.0">
> The "LimitLoadToSessionType" of "Aqua" ensures that the job is only
> loaded into GUI sessions.
I will give LimitLoadToSessionType a spin on Monday. Thanks again.
> The "RunAtLoad" of true means that the job is run once when it's
> loaded (that is, when the GUI session is started). And the absence
> of "KeepAlive" or "OnDemand" means that the job is not
> automatically relaunched when it exits.
> Quinn "The Eskimo!" <http://www.apple.com/
> Apple Developer Relations, Developer Technical Support, Core OS/
> launchd-dev mailing list
> launchd-dev at lists.macosforge.org
More information about the launchd-dev