Re: AppleScript in Sandboxed App
Re: AppleScript in Sandboxed App
- Subject: Re: AppleScript in Sandboxed App
- From: John Nairn <email@hidden>
- Date: Tue, 15 Jan 2013 19:44:26 -0800
Thanks. I watched the one on "Seccure Automation Techniques in OS X." Near the end it said exactly what I wanted to hear which is that application-run scripts that target only themselves have no restrictions. So far it is half true in my app. I can run an AppleScript now without troubles. But many of my scripts are in python and use ScriptingBridge. I run these python scripts by launching an NSTask as follows
1. set working directory to path for the script (which is in my sandbox)
2. set PYTHONPATH to some app-specific folders (all in my sandbox)
3. Launch task with command line like
/usr/bin/python (path_to_script)
The task actually starts fine and python launches. The first step in every script is to connect to my app using ScriptingBridge with a python line like
_gedit = SBApplication.applicationWithBundleIdentifier_(appID)
but this fails with error message
2013-01-15 19:26:38.954 Python[44491:1407] warning: failed to get scripting definition from /Users/nairnj/Library/Developer/Xcode/DerivedData/GEDitCOM_Pro-bimxoxdrzkwdkqgvskiwmvgvydje/Build/Products/Develop/GEDitCOM SD.app; it may not be scriptable.
Of course that is not true because the app is scriptable and works fine with AppleScript and with python when not sandboxed.
I was thinking my app is just receiving AppleEvents (as generated by python and ScriptingBridge), which is supposed to be allowed. But it does not work. The video mentions a new 10.8 class called NSUserUnixTask, which sounded promising, but its documentation specificlally says "The class is not intended to execute scripts built into an application; for that, use one of the NSTask... " Well I want to execute built in scripts so I am using NSTask, but so far without success.
Has anyone be able to use NSTask to execute a python script to interact only with your own sandboxed app using ScriptingBridge?
John Nairn
On Jan 14, 2013, at 9:59 AM, Mike Abdullah wrote:
>
> On 14 Jan 2013, at 17:50, John Nairn <email@hidden> wrote:
>
>> I have sandboxed an app that allows users to run scripts as a major feeature (i.e., dealbreaker on sandboxing only answer is to delete this feature). I was pleased that I can run AppleScripts fine through the sandboxed app from Apple's Script Editor, but the user experience is much (much, much) better if they can select a script from a menu in my app and run it, but that method fails. Here is more info:
>>
>> 1. Script running code is sound and works fine if app is not sandboxed.
>> 2. Script is compiled, error free, and does not try to send events to any app except my own
>> 3. Script is stored in application support of my container and therefore I should have read and write permission on that file
>> 4. The first step in running the script (which is when is fails) is simply:
>>
>> script = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:scriptPath] error:&errorInfo];
>>
>> The errorInfo dictionary has only NSAppleScriptErrorNumber = -43 and no other details. I could not find this error number in a google search.
>>
>> 5. I have more problems running python scripts using Scripting bridge when sandboxed, but I am working on one problem for now
>
> Go watch the sandboxing videos from WWDC this year. They cover automation quite a bit, and all will be made much clearer.
>
------------
John Nairn
http://www.geditcom.com
Genealogy Software for the Mac
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden