Getting the results out of Applescript
Getting the results out of Applescript
- Subject: Getting the results out of Applescript
- From: Mike Abdullah <email@hidden>
- Date: Sat, 7 Jan 2006 13:12:49 +0000
I am having difficulties trying to get an AppleScript to work with my
app. Basically I have placed the script inside the resources folder
of my app, and I have written code that will run the script no
problem. However, I cannot figure out how to get the results of my
script. The script (ideally) does something like this:
return {value1:"foo1", value2: "foo2"}
This should (if I have understood things properly, correspond to an
NSDictionary). So how do you actually access these results? I
currently have the following code:
NSURL *scriptURL = [NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource: @"theScript" ofType:
@"scpt"]];
NSDictionary *theDict = [[NSDictionary alloc] init];
NSAppleEventDescriptor *desc;
NSAppleScript *theScript = [[NSAppleScript alloc]
initWithContentsOfURL: scriptURL error: &theDict];
desc = [theScript executeAndReturnError: &theDict];
[theScript release];
[theDict release];
So, if I understand it, the values returned by the script are now
stored in desc. However, how do I get them out? I see there is a
method for getting string values, data, and one that looks like it
probably does records and lists, button I cannot persuade it to work.
I also tried having the script simply do:
return "foo"
and then did [desc stringValue] but all I got printed to the log was
a sequence of numbers, which, bizzarley change each time the script
is run - surely it should be the same result each time!
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden