ASObjC in 'Cocoa Application' Xcode project (not 'Cocoa-AppleScript')

I have a project using CocoaPods that I’d like to write in ASObjC. It’s a project with AppDelegate.h instead of AppDelegate.applescript. Is this possible? I thought I saw mention of it on one of these forums but haven’t been able to find it.

Hello. I’m not exactly sure what you mean, but could it be that you want to create real Cocoa app (ObjC + C) and add an applescript class to command another app, sending messages to methods in ASOC from Cocoa?

If that’s the case, this is entirely possible. It’s a bit tricky, but not too hard. I can guide you through it.

Browser: Safari 537.78.2
Operating System: Mac OS X (10.8)

Yes, I want to create a real Cocoa app because the CocoaPods project is in Objective-C (which I know next to nothing about). It’s not that I necessarily need to use AppleScript to control other apps. Rather I’m familiar with ASObjC so I’d like to do as much of the coding as possible in ASObjC and not Objective-C (which as I said I’m not familiar).

I realize what I’m asking may seem absurd. Please tell me if it would be simpler for me to just learn Objective-C (which seems like a daunting endeavor). I was just hoping there would be a few lines of code in Objective-C that would tell my project to use the code I’ve written in AppleScript and ASObjC. Furthermore, I’d like to link my ASObjC handlers to buttons on the interface…

I see. In that case, perhaps I should create a tiny project that demonstrates the whole concept. You could base you project off of that one.

Which version of Xcode are you using?

Basically you can use AppleScriptObjC in Cocoa projects and vice versa.
In a Cocoa project you have to load the AppleScriptObjC framework and call loadAppleScriptObjectiveCScripts of NSBundle (usually in main.m).

The procedure to implement AppleScriptObjC scripts in Cocoa projects is described in Shane’s book and also in a couple of threads here on this forum

I’m using version 6.2

Would it be helpful if I showed you a sample Cocoa-AppleScript project I’ve built that basically illustrates what I want to do? Then you could walk me though how to make the same thing in an Objective-C project.

I’ve looked at a few threads but it seems they all assume I have basic knowledge of Objective-C syntax. I’m still lost.

Here’s an example Cocoa-Applescript project that Shane Stanley helped me with last night:

AppDelegate.applescript (on modifyXML:sender is linked to a button on the UI)

script AppDelegate
	property parent : class "NSObject"
	-- IBOutlets
	property theWindow : missing value
	on applicationWillFinishLaunching_(aNotification)
		-- Insert code here to initialize your application before any files are opened 
	end applicationWillFinishLaunching_
	on applicationShouldTerminate_(sender)
		-- Insert code here to do any housekeeping before your application quits 
		return current application's NSTerminateNow
	end applicationShouldTerminate_
    on modifyXML:sender
        set thePath to POSIX path of (choose file of type {"xml"})
        set theURL to current application's NSURL's fileURLWithPath:thePath
        set aURL to current application's |NSURL|'s fileURLWithPath:thePath -- make NSURL
        set theXMLDoc to current application's NSXMLDocument's alloc()'s initWithContentsOfURL:aURL options:0 |error|:(missing value)
        set theClipArray to theXMLDoc's nodesForXPath:"/fcpxml/library/event/project/sequence/spine/clip" |error|:(missing value)
        set theClip to theClipArray's objectAtIndex:0
        set theAttr to theClip's attributeForName:"name"
        theAttr's setStringValue:"this is a test"
        current application's NSLog("%@", theXMLDoc)
    end modifyXML:
end script

What might the procedures be to put this in an Objective-C project?

But why do you need to absolutely use CocoaPods with ASOC ? what is your goal exactly? Because if the integration with Objective C code is giving you trouble and you know nothing about ObjC, then you are in for a ride.

The way I usually use ASOC in my apps always follow the same logic: all of the app runs in cocoa, except for the parts where I need to control another app. The way I believe you are trying to use it is the reverse. You want an ASOC app with access to ObjC methods for things that don’t exist in AppleScript. Am I understanding this right?

Yes, I want a ‘Cocoa Application’ that primarily uses ASOC. I need CocoPods to call methods from a third party API. I believe those methods could also be called using ASOC. Is this possible or should I go learn Objective-C.

No you don’t need to learn ObjC, but knowing the basics won’t hurt in a project like yours.

Do you have Shane’s book? I believe there is a section on how to use Cocoa inside an ASOC app. Chapter 16 in my version (3.0). That would be an excellent start.

If you told us what exactly you want to use, you might get a more specific answer.

I apologize for my lack of detail. In order to understand what I want to do, you need to understand what my job is. I work in broadcast news as a video editor and we use Final Cut Pro X (don’t laugh, it’s a legitimate pro app if your willing to work around its quirks). All of our videos follow the same format, the same elements, the same overlays, the same effects. About a year ago, I built a pretty primitive app that modifies an xml file from Final Cut and effectively creates a template so we no longer have to go through the process of applying effects, overlays, video formatting, audio formatting, etc. each time we start a new project (which is up to 70 times per day). The second piece to the puzzle is our project management software. We use Podio which is a webapp that basically keeps the writers, anchors, editors, and publishers on the same page (which story is higher in priority to be edited what text elements need to be added what graphics need to be created). Podio has an API (PodioKit) and an Objective-C client library which they encourage their users to use CocoaPods to integrate into their project.

What I’d like to do is integrate the project information on our project management platform (Podio: with our XML-template so that many of the repetitive tasks can be automated. These tasks mostly have to do with adding the text overlays that appear in every video (think of the text you see over the anchor’s shoulder while he/she is reading the news). But this could also be taken to a much higher level (specifying graphical elements and maps) .

I’m pretty motivated to make this happen but I’m not sure how much knowledge I need. Will I need to go through an Objective-C training or can I get by with my current familiarity with ASOC?

You could probably get some of that working, but honestly I suspect you’d be better off taking the plunge into Objective-C. Once you start getting into Web-based stuff you’re more in the land of asynchronous APIs, and the ability to do stuff on multiple threads tends to become more important.

I’ve wanted to learn Objective-C. It seems I now have more than enough reasons to do so. Do you know of any online training courses you could recommend?

Not really – I tend to prefer books, and I’m not up-to-date on them. Just try to find something aimed at OS X and not iOS. A basic primer in C is probably the best place to start. Good luck!