首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Launchd PLIST不运行

Launchd PLIST不运行
EN

Stack Overflow用户
提问于 2009-08-06 00:51:48
回答 2查看 2.7K关注 0票数 2

我试图在launchd plist中运行一个Applescript,但由于某种原因,它只是不起作用。它可能是我的电脑,但我在想,它可能有其他问题。如果有人能看一看并评论这篇文章,我会非常感激的!

代码语言:javascript
复制
<?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:

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

发布于 2009-08-12 10:25:34

一个可能的问题是,launchd没有在登录用户的GUI上下文中执行您的AppleScript,因此AppleScript无法与查找程序对话。

确保plist安装为LaunchAgent,而不是LaunchDaemon ( plist应该位于/Library/LauchAgents或~/Library/LaunchAgents中)。

尝试将以下内容添加到plist中,以使脚本在GUI上下文中运行:

代码语言:javascript
复制
<key>LimitLoadToSessionType</key>
<string>Aqua</string>

请注意,这只能在10.5及以上版本上可靠地工作;我无法使每个用户的LaunchAgents在10.4上正确工作。

票数 1
EN

Stack Overflow用户

发布于 2009-08-14 17:34:22

我认为您需要将最后的参数分解为单独的参数--每个参数( -e和AppleScript的各个行)都应该位于一个单独的<string />元素中。或者,正如Nick所说,只要传入一个包含整个脚本的.applescript文件即可。

问题是您的命令被解释为:

代码语言:javascript
复制
/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\''

这不是你的意思。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1236471

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档