• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Swift + AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swift + AppleScript


  • Subject: Re: Swift + AppleScript
  • From: Neil Faiman <email@hidden>
  • Date: Tue, 04 Oct 2016 05:34:44 -0400
  • X_cmae_category: , ,

> On Oct 3, 2016, at 11:30 PM, Shane Stanley <email@hidden> wrote:
>
> On 4 Oct. 2016, at 1:59 pm, Neil Faiman <email@hidden> wrote:
>>
>> Is there a straightforward way to put together an app containing both Swift (or ObjC) and AppleScript code, where the main program is Swift, but it calls into AppleScript to do particular functions?
>
> If it's only a small amount of code you can use NSAppleScript, although that still leaves you the job of unpacking the descriptor results, which can be tedious depending on what you are doing.
>
> The other way is to use AppleScriptObjC. You put your scripts in an AppleScript .scpt file in your app's /Contents/Resources, import the AppleScriptObjC framework, and call [[NSBundle mainBundle] loadAppleScriptObjectiveCScripts] early on. Your scripts should be of the form of a script object with a Cocoa class as parent and the handlers in a form compatible with Objective-C conventions:
>
> script SomeClassName
> 	property parent: class "NSObject"
>
> 	on doStuff()
> 	--
> 	end doStuff
>
> 	on doStuffWith:x
> 		set x to x as integer
> 		return x * 2
> 	end doStuffWith:
>
> end script
>
> You then include the handlers in an @nterface file for the "class", and instantiate your instance:
>
>       self.helperASObject = [[NSClassFromString(@"SomeClassName") alloc] init];
>
> and essentially treat it like a Cocoa class:
>
> NSUInteger val = [self.helperASObject doStuffWith:@4];
>
> The scripting bridge will then convert the common classes (NSString, NSNumbers, NSArray, NSDictionary, etc).

OK, That sounds worth experimenting with.

Thanks for the explanation. I was sure there was a way to accomplish it (I’ve been reading this list for years, and did a substantial ASOC project some years ago), but wasn’t clear at all on the details.

	Neil


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden


References: 
 >Swift + AppleScript (From: Neil Faiman <email@hidden>)
 >Re: Swift + AppleScript (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Swift + AppleScript
  • Next by Date: Re: Swift + AppleScript
  • Previous by thread: Re: Swift + AppleScript
  • Next by thread: Re: Swift + AppleScript
  • Index(es):
    • Date
    • Thread