当我将 OS X 升级到 10.9 时,我的 applescript 不再起作用 [英] My applescript doesn't work any more when I upgrade my OS X to 10.9

查看:23
本文介绍了当我将 OS X 升级到 10.9 时,我的 applescript 不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The following code is trying to open the proxies settings dialog,

 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.苹果脚本的第二部分,

it has been working well until I upgrade my Mac OS to 10.9. The second part of the 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 

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

it doesn't work any more. so if any one could tell me the reason, I would be very grateful.

这是我的 .entitlements 文件信息,

edit: Here is my .entitlements file information,

  <?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>

推荐答案


更新答案

在我以前从未使用过的沙盒游戏中玩了一会儿:我使用了这个选项:

Ok after a little play with sandboxing which I have never used before: I used the option :

但是,对于专门提供脚本访问的应用程序组,您可以向这些应用程序发送适当的 Apple 事件,如果您应用包含脚本目标权利.

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.

对于其他应用程序,通过使用临时例外权利,您可以启用将 Apple 事件发送到特定应用程序列表您指定的,如权利密钥参考中所述.

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.

在权利文件中也是如此.

So in the Entitlements file.

您需要添加授权:

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

将其设置为数组

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

Then add two items to it.

com.apple.systempreferences

com.apple.systemevents

这些项目应该是字符串

保存文件.

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

This is All I have done and there are no other entitlements added

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

On my tests the System prefs opened and the Proxies tab was selected.

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

This also shows any App you that even if you tell one app to tell another app/process ..do something. Both apps must be in the list

对您的设置稍作更改即可解决您的问题:

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

By doing this I notice that in your edit you show you have added:

com.apple.preferences.

com.apple.preferences.

所以你只需要把它改成正确的 id,即 com.apple.systempreferences

So you just need to change it to the correct id which is com.apple.systempreferences

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

If you read the AboutAppSandbox link I provided you in the comments. Which I suggested as I assumed your app was sandboxed already. You should have seen:

在辅助应用中使用无障碍 API 借助应用沙盒,您可以并且应该使您的应用程序具有可访问性,如中所述OS X 的辅助功能概述.但是,您不能将辅助应用程序,例如屏幕阅读器,您不能对应用程序进行沙盒处理控制另一个应用程序.

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.

(我真的只是自己读过这个)

( I have literally just read this myself )

这意味着对于辅助应用程序中的可访问性 API 和 Sandoxing,您可以选择其中之一,但不能同时进行.

This implies with regards to accessibility APIs in assistive apps And sandoxing, you can do one or the other but not both.

然而也有这一点,但你需要调查它的影响

There is however this bit also but you will need to investigate its implications

但是,对于专门提供脚本访问的应用程序组,您可以向这些应用程序发送适当的 Apple 事件,如果您应用包含脚本目标权利.

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.

对于其他应用程序,通过使用临时例外权利,您可以启用将 Apple 事件发送到特定应用程序列表您指定的,如权利密钥参考中所述.

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.

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

And reading further there is another possible approach

最后,您的应用程序可以使用 NSUserScriptTask 类的子类来从特殊目录中运行用户提供的 AppleScript 脚本,NSApplicationScriptsDirectory (~/Library/Application脚本/代码签名标识符/).虽然你的应用可以读取文件在该目录下,不能向该目录写入文件;这用户必须在这里手动放置脚本.有关详细信息,请参阅NSUserScriptTask 和 WWDC 2012 的文档:安全自动化OS X 中的技术.

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 中的元素树更改或用户交互将焦点从系统事件的预期目标上移开.


The strategy you are using is not what I would want from an app. And I think using GUI like this leaves a lot of room for it to fail.Either because of element tree changes in the GUI or user interaction takes focus away from the intended target of the system events.

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

I think the better approach would be to inform the user to change the proxy their selves.

这篇关于当我将 OS X 升级到 10.9 时,我的 applescript 不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆