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

查看:93
本文介绍了当我将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之前一直运行良好. Applescript的第二部分,

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.

因此在权利"文件中.

您需要添加权利:

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天全站免登陆