2009-08-06 3 views
2

launchd plist 내에서 AppleScript를 실행하려고하지만 어떤 이유로 작동하지 않습니다. 그것은 내 컴퓨터 일 수 있지만, 거기에 뭔가 다른 것이있을 수 있다고 생각하고 있습니다. 누군가이 글에 대해 살펴보고 의견을 제시 할 수 있다면 정말 고맙겠습니다.Launchd 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"' -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> 

어떤 도움을 주셔서 감사합니다!

최신 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> 

답변

1

가능성이 문제 launchd에가 당신의 애플 스크립트를 실행되지 않는 것입니다 사용자의 GUI 컨텍스트에서-기록, 따라서 애플 스크립트는 찾기 이야기 할 수 없다.

plist가 LaunchAgent가 아닌 LaunchDaemon으로 설치되어 있는지 확인하십시오 (plist는/Library/LauchAgents 또는 ~/Library/LaunchAgents에 있어야합니다).

시도는 GUI 환경에서 실행되는 스크립트를 생성하기 위해서는, PLIST에 다음을 추가 :

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

이는 위의 10.5에서 안정적으로 작동합니다 참고; 10.4에서 사용자 당 LaunchAgent가 올바르게 작동하지 못했습니다.

+0

안녕하세요 Nick : 답장을 보내 주셔서 감사합니다. 불행히도 LimitLoadToSessionType 코드를 사용하고 경로에 파일이 있는지 다시 확인한 후에도 여전히 실행되지 않습니다. 정말 이상한데, 특히 터미널에서 같은 코드를 실행할 때 잘 작동합니다 ... 어떤 아이디어입니까? – PF1

+1

또 다른 아이디어 : applescript 명령을 인수로 전달하는 대신 별도의 스크립트 파일에 넣고 해당 경로를 osascript에 전달하십시오. –

1

최종 인수를 별도의 인수로 나누어야한다고 생각합니다. 각 인수 (-e 및 AppleScript의 개별 줄)는 별도의 <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\'' 

.

+0

Hi Graham : 당신이 제안한 것을 수행했지만, 이제는 StandardErrorPath를 사용하여 문제를 기록 할 때 다음과 같은 오류가 발생합니다. 0 : 1 : 구문 오류 : 알 수없는 토큰을 여기에 놓을 수 없습니다. (-2740) – PF1

+0

스크립트 편집기에서 정확히 같은 스크립트를 실행하면 오류가있는 위치를 알려줍니다? –

+0

아니요, 스크립트 편집기의 유일한 차이점은 AppleScript 문서로 포맷 된 것입니다. 이것은 잘 작동합니다. 그리고 동일한 코드가 터미널에서 정상적으로 실행되며 오류가 발생하지 않습니다. 그 코드가 당신에게 효과가 있습니까? – PF1

관련 문제