2

launchd plist 内で Applescript を実行しようとしていますが、何らかの理由で機能しません。それは私のコンピューターかもしれませんが、何か他の問題があるのではないかと考えています。誰かがこの投稿を見てコメントしてくれたら、本当に感謝します!

<?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.pf.Testing</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>-e</string>
<string>'tell application "Finder"' -e  'set didQuit to (path to home folder as string) &amp; ".myApp"' -e 'if (exists file didQuit) then' -e 'tell application "TestApp"' -e 'activate' -e 'end tell' -e 'end if' -e 'end tell'</string>
</array>
<key>StartInterval</key>
<integer>20</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</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.pf.Testing</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/osascript</string>
<string>-e</string>
<string>'tell application "Finder"'</string>
<string>-e</string>
<string>'set didQuit to (path to home folder as string) &amp; ".myApp"'</string>
<string>-e</string>
<string>'if (exists file didQuit) then'</string>
<string>-e</string>
<string>'tell application "TestApp"'</string>
<string>-e</string>
<string>'activate'</string>
<string>-e</string>
<string>'end tell'</string>
<string>-e</string>
<string>'end if'</string>
<string>-e</string>
<string>'end tell'</string>
</array>
<key>StandardErrorPath</key>
<string>/Users/pf/Desktop/Problem.log</string>
<key>StartInterval</key>
<integer>20</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
4

2 に答える 2

1

考えられる問題は、launchd がログイン ユーザーの GUI コンテキストで AppleScript を実行していないため、AppleScript が Finder と通信できないことです。

plist が LaunchDaemon ではなく、LaunchAgent としてインストールされていることを確認します (plist は /Library/LauchAgents または ~/Library/LaunchAgents に配置する必要があります)。

スクリプトを GUI コンテキストで実行するには、次を plist に追加してみてください。

<key>LimitLoadToSessionType</key>
<string>Aqua</string>

これは 10.5 以降でのみ確実に機能することに注意してください。10.4 では、ユーザーごとの LaunchAgent を正しく動作させることができませんでした。

于 2009-08-12T10:25:34.067 に答える
1

最終的な引数を別々の引数に分割する必要があると思います.各引数( -eAppleScriptの個々の行)は別々の<string />要素にする必要があります. それか、ニックが言うように、.applescriptスクリプト全体を含むファイルを渡すだけです。

問題は、コマンドが次のように解釈されることです。

/usr/bin/osascript -e '\'tell application "Finder"\' -e  \'set didQuit to (path to home folder as string) & ".myApp"\' -e \'if (exists file didQuit) then\' -e \'tell application "TestApp"\' -e \'activate\' -e \'end tell\' -e \'end if\' -e \'end tell\''

これはあなたが意図したものではありません。

于 2009-08-14T17:34:22.533 に答える