The ~ / Library / LaunchAgents plugin is executed manually, but not automatically

I am starting to work with launchd and I want to configure the plist file in such a way that whenever I insert an SD card into my Mac mini-server (with Snow Leopard Server), I want to run a shell script (which should copy all jpg files, rename them, etc.).

So, I created a plist file in ~ / Library / LaunchAgents (see its contents below - it should look for changes in / Volumes), and I created a shell script that says "beep" - this will do something more useful later.

The plist file is logged in using launchctctl, and when I run it (startctl start com.peters.runwhenSDmount), the computer beeps whenever the memory card is connected to the network and remains silent when there is no memory card. Thus, apparantly plist calls the shell script, which subsequently checks for a specific SD card. I guess this also proves that there are no permissions issues for the SD card.

But it doesn't seem to work on its own ??? Any idea why?


plist file: ~ / Library / LaunchAgents / com.peters.runwhenSDmount.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<dict>
    <key>Label</key>
    <string>com.peters.runwhenSDmount</string>
    <key>LowPriorityIO</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
    <string>/Users/peter/Library/Scripts/runwhenSDmount</string>
    </array>
    <key>ThrottleInterval</key>
    <integer>10</integer>
    <key>WatchPaths</key>
    <array>
    <string>/Volumes</string>
    </array>
</dict>
</plist>

shell script: ~ / Library / Scripts / runwhenSDmount

#!/bin/bash
if [ -d "/Volumes/NIKON D40X" ]; then
    say beep
fi
+5
source share
3 answers

, ~/Library/LaunchAgents, launchd. :

  • . - , , ~/Library/LaunchAgents plist.

  • plist "launchctl". :

    launchctl load {Path-to-plist}
    

launchctl , plist. :

launchctl unload {Path-to-plist}

launchctl Plists, / . , plist, , .

+7

~/Library/LaunchAgents, NONE *.plist.

~/Library/LaunchAgents, plist. reset .

chmod 700 ~/Library/LaunchAgents.

: (2015-02-23)

LaunchRocket, Mac PreferencePane . homebrew homebrew.

, , .

+6

, :

As a side note: Brett Terpstra (who does a ton of great work with the Mac on things like nvAlt ) recently commented on his “ Launching tasks remotely with notifyutil and launchdmessage , which he used to use Lingon but recently used LaunchControl. Any of them are worth a look.

+2
source

All Articles