2013-01-01 9 views
6

con uno strano problema qui. Ho ~/Library/LaunchAgents/com.me.helloworld.plist con il seguente contenuto:launchd: WatchPath non attiverà il semplice script "ciao mondo" (OS X 10.8)

<?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.me.helloworld</string> 
     <key>ProgramArguments</key> 
     <array> 
       <string>/Users/me/temp/test.sh</string> 
     </array> 
     <key>WatchPaths</key> 
     <array> 
       <string>/Users/me/temp/Journal.txt</string> 
     </array> 
</dict> 
</plist> 

L'idea è, se ~/temp/Journal.txt viene modificata, deve essere avviata a ~/temp/test .sh. test.sh ha il seguente contenuto:

#!/bin/bash 
echo "hello world from test.sh" >> itchanged.txt 

Quindi, se cambio Journal.txt, dovrei ottenere un file chiamato itchanged.txt. Quando faccio quanto segue:

$ launchctl unload ~/Library/LaunchAgents/com.me.helloworld.plist 
$ launchctl load ~/Library/LaunchAgents/com.me.helloworld.plist 
$ touch Journal.txt 

Fare un ls mostra che test.txt non è stato creato. Tuttavia, se eseguo manualmente un file ./test.sh, viene creato itchanged.txt. Quindi il problema sembra essere da qualche parte nel riconoscere che Journal.txt è cambiato ed eseguire lo script quando questo accade.

Sto usando OS X Mountain Lion. Qualche idea?

risposta

7

Lo script non specifica un percorso per itchanged.txt; poiché la directory di lavoro predefinita per i processi avviati da start è /, e probabilmente il tuo account non dispone delle autorizzazioni per creare file, itchanged.txt non verrà mai creato. È necessario specificare un percorso nello script o aggiungere la chiave WorkingDirectory al file .plist per modificare il valore predefinito.

+0

Questo ha funzionato! Grazie mille, Gordon. – user1940620