启动PLIST未运行
问题描述:
我试图在启动plist内运行Applescript,但由于某种原因,它只是不工作。这可能是因为它是我的电脑,但我认为它可能有其他问题。如果有人可以看看这篇文章并发表评论,我会非常感激!启动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) & ".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) & ".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>
答
一个可能的问题是launchd会不执行你的AppleScript登录的用户的GUI语境,因此AppleScript的不能谈论到Finder。
确保plist安装为LaunchAgent,而不是LaunchDaemon(plist应位于/ Library/LauchAgents或〜/ Library/LaunchAgents中)。
尝试添加以下的plist中,以使在GUI上下文中运行该脚本:
<key>LimitLoadToSessionType</key>
<string>Aqua</string>
注意,这只会在10.5及以上的可靠工作;我无法让每个用户的LaunchAgents在10.4上正常工作。
答
我认为你需要将你的最终论证分解成单独的参数 - 每个参数(-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\''
这是不是你的意思。
嗨昵称: 感谢您的回复。不幸的是,即使在使用LimitLoadToSessionType代码并仔细检查路径中是否存在文件后,它仍然无法运行。这真的很奇怪,尤其是因为当我在终端中运行相同的代码时,它工作得很好......任何想法? – PF1 2009-08-12 17:01:21
另一个想法:不要将applescript命令作为参数传递,而是尝试将它们放入单独的脚本文件中,并将其路径传递给osascript。 – 2009-08-13 12:07:05