来自 launchd 的 NSAppleScript
我有一个 launchd 服务和一个 Cocoa 应用程序。当用户从应用程序文件夹中单击该应用程序时,该应用程序就会运行。我想从服务执行以下 Apple 脚本。但即使在 xcode 的调试版本中似乎可以工作,但当它作为 launchd 服务构建和安装时,它就不起作用。
NSString* path = @"/Applications/Sample.app/Contents/Resources/reset.scpt";
NSURL* url = [NSURL fileURLWithPath:path];
NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript =
[[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];
[appleScript release];
I have a launchd service and a Cocoa app. The app runs when the user clicks on it from the application folder. I want to execute the following Apple Script from the service. But even though appears to work in the debug version in xcode, it does not work when it is built and installed as launchd service.
NSString* path = @"/Applications/Sample.app/Contents/Resources/reset.scpt";
NSURL* url = [NSURL fileURLWithPath:path];
NSDictionary* errors = [NSDictionary dictionary];
NSAppleScript* appleScript =
[[NSAppleScript alloc] initWithContentsOfURL:url error:&errors];
[appleScript executeAndReturnError:nil];
[appleScript release];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的 launchd
.plist
文件有问题。launchd 的一个常见错误是:launchd 不是 shell。
当尝试使用 launchd 执行 Apple 脚本时,尝试将其传递给 shell:
将
.plist
放入~/Library/LaunchAgents/YOUR.LABEL.plist
(文件名有与Label
值相对应)然后加载 plist 文件:
MacOS 缓存 plist 文件。因此,如果您已经有代理的 plist 文件:注销并再次登录以刷新缓存。
现在启动代理:
请参阅:https://launchd.info/ 了解更多信息。
I'm assuming there is a problem with your launchd
.plist
file.A common mistake with launchd is: launchd is not shell.
When trying to execute the apple script with launchd try to pass it to shell:
Place the
.plist
in~/Library/LaunchAgents/YOUR.LABEL.plist
(The filename has to correspond with theLabel
value)Then load the plist file:
MacOS caches the plist file. So if you already have a plist file for your agent: Logout and login again to refresh the cache.
Now start the agent:
See: https://launchd.info/ for more info.