启动 PLIST 未运行
我试图在 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) & ".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) & ".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>
I am attempting to run an Applescript inside a launchd plist, but for some reason it just isn't working. It could be that it is my computer, but I am thinking that there may be something else wrong with it. If someone could take a look and comment on this post, I would really appreciate it!
<?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>
Thanks for any help!
LATEST 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个可能的问题是 launchd 没有在登录用户的 GUI 上下文中执行您的 AppleScript,因此 AppleScript 无法与 Finder 通信。
确保 plist 作为 LaunchAgent 安装,而不是 LaunchDaemon(plist 应位于 /Library/LauchAgents 或 ~/Library/LaunchAgents 中)。
尝试将以下内容添加到 plist 中,以使脚本在 GUI 上下文中运行:
请注意,这仅在 10.5 及更高版本上可靠运行; 我无法让每用户 LaunchAgents 在 10.4 上正常工作。
A likely problem is that launchd is not executing your AppleScript in the logged-in user's GUI context, and therefore AppleScript can't talk to the Finder.
Make sure the plist is installed as a LaunchAgent, and not a LaunchDaemon (the plist should be located in /Library/LauchAgents or ~/Library/LaunchAgents).
Try adding the following to the plist, to make the script run in the GUI context:
Note that this will only work reliably on 10.5 and above; I was not able to get per-user LaunchAgents working correctly on 10.4.
我认为您需要将最终参数分解为单独的参数 - 每个参数(元素。 或者,或者正如尼克所说,只需传入包含整个脚本的
-e
和 AppleScript 的各个行)应该位于单独的.applescript
文件。问题是您的命令被解释为:
这不是您的意思。
I think you need to break your final argument up into separate arguments - each argument (the
-e
and the individual lines of AppleScript) should be in a separate<string />
element. Either that, or as Nick says just pass in a.applescript
file with the whole script in.The problem is that your command gets interpreted as:
which isn't what you meant.