启动 PLIST 未运行

发布于 2024-07-29 19:00:27 字数 2346 浏览 3 评论 0原文

我试图在 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>

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别忘他 2024-08-05 19:00:27

一个可能的问题是 launchd 没有在登录用户的 GUI 上下文中执行您的 AppleScript,因此 AppleScript 无法与 Finder 通信。

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

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

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

请注意,这仅在 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:

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

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.

向日葵 2024-08-05 19:00:27

我认为您需要将最终参数分解为单独的参数 - 每个参数(-e 和 AppleScript 的各个行)应该位于单独的 元素。 或者,或者正如尼克所说,只需传入包含整个脚本的 .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\''

这不是您的意思。

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:

/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\''

which isn't what you meant.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文