Re: Sending a list of path strings to the Finder via Scripting Bridge
Re: Sending a list of path strings to the Finder via Scripting Bridge
- Subject: Re: Sending a list of path strings to the Finder via Scripting Bridge
- From: Peter <email@hidden>
- Date: Sat, 26 May 2012 16:30:20 +0200
Thank you! You might want to add this to an appendix of your book some time.
Am 26.05.2012 um 14:58 schrieb Shane Stanley:
> On 26/05/2012, at 10:25 PM, Peter wrote:
>
>> On the other hand I have never seen/never tried to call AppleScript from Cocoa in AppleScriptObjC terms - if this wording makes sense at all. I don't remember reading about this in your book, which focuses of course on accessing Cocoa from AppleScript.
>
> It's not in the book, but it's pretty simple. You just need to stick to passing objects of the main classes (NSString, NSArray, NSNumber, NSDictionary, NSData) and coercing them in the receiving handler. So in this case you might have an AS "class" with a handler like this:
Just for clarification:
This AS handler would then live in a .applescript file in my project wrapped in
script ASClassInstance
> on selectItemsInFinder_(arrayOfPaths)
> set arrayOfPaths to arrayOfPaths as list -- coerce from pseudo-pointer to AS object
> set fileList to {}
> repeat with aPath in arrayOfPaths
> set end of fileList to aPath as POSIX file
> end repeat
> tell application "Finder" to select fileList
> end selectItemsInFinder_
end script
> And you can call it as either a class or instance method:
>
> NSArray *array = *paths*
> [ASClassInstance selectItemsInFinder:array];
>
> or:
>
> [[ASClassName alloc] init] selectItemsInFinder:array];
>
> or:
>
> [ASClassName selectItemsInFinder:array];
And on of the above calls would live in a .m file containing
#import <AppleScriptObjC/AppleScriptObjC.h> //no need to put this in main.m, I guess
in a project with the AppleScriptObjC linked in.
Is this correct? Does this require any special build settings?
Thanks!
___ Peter Hartmann ________
mailto:email@hidden
_______________________________________________
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