Import / Convert your AppleScript into a Xcode Cocoa AS project

I haven’t been able to find any clear info on how to import a completed AppleScript / ASApp into Xcode. I’d like to further develop my applescript using some better user interfacing

I’ve found the Cocoa AS App template.
And it say insert code here in the AppDelegate.applescript

Do I:

  • Repaste my code into the AppDelegate.applescript
  • Add MyOwnApp.applescript as a file and add to MyOwnApp.applescript either :
    • reference the AppDelegate as a parent
    • add my own property parent : class “NSObject”

Do I need to and script at the beginning and end, like in the AppDelegate.applescript?
How about the name that I call said script? Can I name it anything or should it be called
the same as the name of the script. (as in the template)… so something like

script MyOwnApp
-- all of my original AS code in here?
end script

next question is how are the following handled:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use framework "VVMIDI" -- private framework
use script "BridgePlus"

will the Xcode project / MyOwnApp.applescript compile properly?

Do I need to add those frameworks to my Xcode project and then
add import statements to the main.m file?

What frameworks do I need to embed?
I know I need to embed the private framework VVMIDI.
I also know that the framework VVMIDI depends on two other frameworks.
Do I need to add those to the Xcode project as well or is there away I can get
Xcode to “know” via the VVMIDI framework that it also needs to import anything
that other frameworks are linked too.

Do I add the script libraries to a Resources/Scripts folder?

thanks

The applicationWillFinishLaunching: handler is where you put code you want to run as soon as the app is launched – set-up code, if you like.

That’s generally the most convenient. Presumably you UI will have button(s) or other controls to trigger your code, and you put it in the relevant action handlers.

You can add your own class files, but it’s often just unnecessary complication.

You add frameworks in the standard Xcode way, not via use statements. In the case of BridgePlus, see the comments towards the end here:

https://www.macosxautomation.com/applescript/apps/BridgePlus.html

There’s no need to add them to main.m – leave it alone.

Try just the VVMIDI framework, but you may have to add the others too. Xcode is a bit smarter about frameworks these days.

Embedded libs should go in a /Contents/Resources/Script Libraries folder. But you may be better off adding their code as a separate class file, and calling them from there.

One other question.

I’m guessing I need to change my handlers context from:


on myFunction:(myVariables)
-- do stuff 
end myFunction

-- change to 
on myFunction_(myVariables)
-- so stuff
end myFunction

In order for Xcode to see the functions as
Action Outlets?

No, although the parens you have there are superfluous. The template still uses the underscore syntax because it was written when that was current.

IMO, you’re better doing your editing in an external editor rather than Xcode, so you can compile, and that will change the syntax anyway.