gpt4 book ai didi

objective-c - 当我将 OS X 升级到 10.9 时,我的 applescript 不再工作

转载 作者:太空狗 更新时间:2023-10-30 03:50:28 25 4
gpt4 key购买 nike

以下代码试图打开代理设置对话框,

 NSAppleScript *a = [[NSAppleScript alloc] initWithSource:@"tell application \"System Preferences\"\nset current pane to pane \"com.apple.preference.network\"\nactivate\nend tell\ntell application \"System Events\" to tell process \"System Preferences\" to tell window 1\n click button -3\nclick radio button -2 of tab group 1 of sheet 1\nend tell"];
[a executeAndReturnError:nil];

在我将我的 Mac OS 升级到 10.9 之前,它一直运行良好。 applescript的第二部分,

 tell application \"System Events\" to tell process \"System Preferences\" to tell window 1\n click button -3\nclick radio button -2 of tab group 1 of sheet 1\nend tell 

它不再起作用了。所以如果有人能告诉我原因,我将不胜感激。


编辑: 这是我的 .entitlements 文件信息,

  <?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>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.preference</key>
<array>
<string>com.apple.preference</string>
<string>com.apple.systemevents</string>
</array>
</dict>
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.preference</string>
<string>com.apple.systemevents</string>
</array>
</dict>
</plist>

最佳答案


更新答案

好吧,在玩了我以前从未使用过的沙盒之后:我使用了选项:

However, for applications that specifically provide scripting access groups, you can send appropriate Apple events to those apps if your app includes a scripting targets entitlement.

For other applications, by using a temporary exception entitlement, you can enable the sending of Apple events to a list of specific apps that you specify, as described in Entitlement Key Reference.

所以在 Entitlements 文件中。

您需要添加权利:

com.apple.security.temporary-exception.apple-events

将其设置为数组

然后向其中添加两个项目。

com.apple.systempreferences

com.apple.systemevents

这些项目应该是字符串

保存文件。

这就是我所做的一切,没有添加其他权利

在我的测试中,系统首选项打开并选择了代理选项卡。

这也会向您显示任何应用程序,即使您告诉一个应用程序告诉另一个应用程序/进程..做某事。两个应用都必须在列表中


对您的设置稍作更改应该可以解决您的问题:

通过这样做,我注意到在您的编辑中您显示您添加了:

com.apple.preferences.

所以你只需要将它更改为正确的 id,即 com.apple.systempreferences


答案原文:


如果您阅读 AboutAppSandbox我在评论中为您提供的链接。这是我建议的,因为我认为您的应用程序已经被沙盒化了。你应该已经看到:

Use of accessibility APIs in assistive apps With App Sandbox, you can and should enable your app for accessibility, as described in Accessibility Overview for OS X. However, you cannot sandbox an assistive app such as a screen reader, and you cannot sandbox an app that controls another app.

(我自己刚刚读过这篇文章)

这意味着关于辅助应用程序中的辅助功能 API 和 sandoxing,您可以做其中之一,但不能同时做。

但是也有这个位,但是你需要调查它的含义

However, for applications that specifically provide scripting access groups, you can send appropriate Apple events to those apps if your app includes a scripting targets entitlement.

For other applications, by using a temporary exception entitlement, you can enable the sending of Apple events to a list of specific apps that you specify, as described in Entitlement Key Reference.

进一步阅读还有另一种可能的方法

Finally, your app can use the subclasses of NSUserScriptTask class to run user-provided AppleScript scripts out of a special directory, NSApplicationScriptsDirectory (~/Library/Application Scripts/code-signing-identifier/). Although your app can read files within this directory, it cannot write files into this directory; the user must manually place scripts here. For details, see the documentation for NSUserScriptTask and WWDC 2012: Secure Automation Techniques in OS X.


您使用的策略不是我想要的应用程序。而且我认为像这样使用 GUI 会留下很大的失败空间。要么是因为 GUI 中的元素树发生变化,要么是用户交互将焦点从系统事件的预期目标上移开。

我认为更好的方法是通知用户自行更改代理。

关于objective-c - 当我将 OS X 升级到 10.9 时,我的 applescript 不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21303292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com