Friday, November 16, 2018

#1 2018-11-02 02:54:36 am

technomorph
Member
Registered: 2017-12-14
Posts: 72

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

Applescript:

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

next question is how are the following handled:

Applescript:

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

Offline

 

#2 2018-11-02 05:09:06 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5470

Re: Import / Convert your AppleScript into a Xcode Cocoa AS project

technomorph wrote:

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



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.

Do I:
- Repaste my code into the AppDelegate.applescript



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.

next question is how are the following handled:

Applescript:

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



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/apples … ePlus.html

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



There's no need to add them to main.m -- leave it alone.

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.



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

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



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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-11-02 10:58:20 pm

technomorph
Member
Registered: 2017-12-14
Posts: 72

Re: Import / Convert your AppleScript into a Xcode Cocoa AS project

One other question.

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

Applescript:


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?

Offline

 

#4 2018-11-02 11:08:22 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5470

Re: Import / Convert your AppleScript into a Xcode Cocoa AS project

technomorph wrote:

I'm guessing I need to change my handlers [...] 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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)