[launchd-dev] Launch shell script when volume is mounted

Matt Calthrop matt at calthrop.com
Tue Apr 19 13:45:43 PDT 2011


Thanks Jerry.

However: the key thing here is that I want to know the name of the
volume that has just been mounted - that information is not passed in
to the script that is executed.

I've tried both the StartOnMount and WatchPaths methods - and both
behave the same way: no name of the the volume just mounted.

Have found another (hacky) way of doing the job; will reply in separate email.

Matt

On 19 April 2011 20:39, Jerry Krinock <jerry at ieee.org> wrote:
>
> On 2011 Apr 18, at 12:32, Matt Calthrop wrote:
>
> > I want to run a shell script whenever a volume is mounted – and the
> > shell script needs to somehow know what the name of the volume is that
> > has just been mounted.
> >
> > I know it can be done (HardwareGrowler does it), but I just haven't
> > found out how yet.
>
> Read:
>
> http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html
>
> You will find:
>
> StartOnMount <boolean>
> This optional key causes the job to be started every time a filesystem is mounted.
>
> And if that doesn't work for some reason, maybe try and "watch" /Volumes using this:
>
> WatchPaths <array of strings>
> This optional key causes the job to be started if any one of the listed paths are modified.


More information about the launchd-dev mailing list