6

ここで奇妙な問題があります。次の内容の〜/ Library / LaunchAgents/com.me.helloworld.plistがあります。

<?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>

アイデアは、〜/ temp / Journal.txtが変更された場合、〜/ temp/test.shを実行する必要があるということです。test.shの内容は次のとおりです。

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

したがって、Journal.txtを変更すると、itchanged.txtというファイルを取得する必要があります。私が次のことをするとき:

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

lsを実行すると、test.txtが作成されていないことがわかります。ただし、手動で./test.shを実行すると、itchanged.txtが作成されます。したがって、問題は、Journal.txtが変更されたことを認識し、これが発生したときにスクリプトを実行することにあるようです。

OS XMountainLionを使用しています。何か案は?

4

1 に答える 1

7

スクリプトはitchanged.txtのパスを指定していません。launchd-startedプロセスのデフォルトの作業ディレクトリは/であり、アカウントにはおそらくそこにファイルを作成する権限がないため、itchanged.txtは作成されません。スクリプトでパスを指定するか、WorkingDirectoryキーを.plistに追加して、デフォルトを変更する必要があります。

于 2013-01-01T09:52:37.273 に答える