My applescript doesn't work any more when I upgrade my OS X to 10.9

Gaojin Hsu

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];  

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.


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

UPDATE TO ANSWER

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

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.

So in the Entitlements file.

You need to add the Entitlement:

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

Set it as an Array

Then add two items to it.

com.apple.systempreferences

com.apple.systemevents

These items should be strings

Save the file.

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


A slight change to your setup should fix your issue:

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

com.apple.preferences.

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


Original part of Answer:


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:

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 )

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

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.

And reading further there is another possible approach

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.


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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

My applescript doesn't work any more when I upgrade my OS X to 10.9

From Dev

Why doesn't my operation work when I use BigDecimal?

From Dev

My effect's doesn't work normally When I Resize

From Dev

My speakers and headphone doesn't work when i connect my headphone to my laptop

From Dev

Sound doesn't work any more on my laptop on speakers neither on headphone

From Dev

When i change my api level my http request doesn't work

From Dev

When I try pause and play in jsFiddle, my code works but it doesn't work in my html page

From Dev

my integer counter doesn't work if i apply more than 1 method

From Dev

Why don't i get any results when my input variable has more than 1 character?

From Dev

I can’t drag any of the icons in my dock in Mac OS X

From Dev

Windows 10 touchpad doesn't work after I use my keyboard for about 3 seconds

From Dev

how can i upgrade my caffe model so it doesn't 'upgrade' every time I use it

From Dev

Why doesn't my CSS work in IE10?

From Dev

My OS X app doesn't want to open files it created

From Dev

Why doesn't the null coalescing operator work on my nullable int when I convert it to a string?

From Dev

My Javascript doesn't work when I put a script element in the head to load it from a URL

From Dev

When I reply to .Prompts.choice() with Direct Line API, my bot doesn't work correctly

From Dev

Clipboard doesn't work when I load my main executable assembly manually

From Dev

why my application doesn't work when I want to create buttons dynamically in android?

From Dev

Why doesn't build-dep work even when I have URIs in my sources list already?

From Dev

Local Notifications are working in the simulator, but doesn't work when i test it on my actual device

From Dev

Why my program doesn't work when I put an Even Number of Elements

From Dev

When I reply to .Prompts.choice() with Direct Line API, my bot doesn't work correctly

From Dev

My css transition doesn't work when I add the <html> tags

From Dev

My script runs fine when I run it from the terminal but it doesn't work with cron. Why?

From Dev

Why my storyboard doesn't work from custom bundle resources when I connected IBOutlet or IBAction?

From Dev

"prepareRenderer" doesn't work when I put data from xml into my customJTable

From Dev

Publish desktop application working fine on my system but when I send setup to someone, it doesn't work

From Dev

I don't how why my backgroundImage doesn't work

Related Related

  1. 1

    My applescript doesn't work any more when I upgrade my OS X to 10.9

  2. 2

    Why doesn't my operation work when I use BigDecimal?

  3. 3

    My effect's doesn't work normally When I Resize

  4. 4

    My speakers and headphone doesn't work when i connect my headphone to my laptop

  5. 5

    Sound doesn't work any more on my laptop on speakers neither on headphone

  6. 6

    When i change my api level my http request doesn't work

  7. 7

    When I try pause and play in jsFiddle, my code works but it doesn't work in my html page

  8. 8

    my integer counter doesn't work if i apply more than 1 method

  9. 9

    Why don't i get any results when my input variable has more than 1 character?

  10. 10

    I can’t drag any of the icons in my dock in Mac OS X

  11. 11

    Windows 10 touchpad doesn't work after I use my keyboard for about 3 seconds

  12. 12

    how can i upgrade my caffe model so it doesn't 'upgrade' every time I use it

  13. 13

    Why doesn't my CSS work in IE10?

  14. 14

    My OS X app doesn't want to open files it created

  15. 15

    Why doesn't the null coalescing operator work on my nullable int when I convert it to a string?

  16. 16

    My Javascript doesn't work when I put a script element in the head to load it from a URL

  17. 17

    When I reply to .Prompts.choice() with Direct Line API, my bot doesn't work correctly

  18. 18

    Clipboard doesn't work when I load my main executable assembly manually

  19. 19

    why my application doesn't work when I want to create buttons dynamically in android?

  20. 20

    Why doesn't build-dep work even when I have URIs in my sources list already?

  21. 21

    Local Notifications are working in the simulator, but doesn't work when i test it on my actual device

  22. 22

    Why my program doesn't work when I put an Even Number of Elements

  23. 23

    When I reply to .Prompts.choice() with Direct Line API, my bot doesn't work correctly

  24. 24

    My css transition doesn't work when I add the <html> tags

  25. 25

    My script runs fine when I run it from the terminal but it doesn't work with cron. Why?

  26. 26

    Why my storyboard doesn't work from custom bundle resources when I connected IBOutlet or IBAction?

  27. 27

    "prepareRenderer" doesn't work when I put data from xml into my customJTable

  28. 28

    Publish desktop application working fine on my system but when I send setup to someone, it doesn't work

  29. 29

    I don't how why my backgroundImage doesn't work

HotTag

Archive