Xcode 4 script class template

If you’re using Xcode 4, you might have noticed that it doesn’t include a template for an AppleScriptObjC class file – you have to add an empty file and do the rest yourself. Not rocket science, but a pain.

I put a simple template together, and wrapped it in an installer app. You can download it from one of the boxes on the side here: www.macosxautomation.com/applescript/apps/.

What the heck. I’ve modified it to also add a new application template. It differs by:

  • Saving scripts in applications as execute-only by default;

  • Fixing the MainMenu.xib file in document-based projects so that the app’s name is entered properly in the Application and Help menus.

  • Changes the default MyDocument.applescript file in document-based projects to get rid of code that doesn’t work, and avoid the use of an AppleScript keyword as an argument variable.

Thanks Shane. In fact, while I’m at it, thanks for the very helpful book and constant help in this forum.

I haven’t made the jump to Xcode 4 because I’ve gotten the impression that it’s not so ASOC friendly. Am I under the wrong impression? I’m sure your template will be very useful, but I seem to remember other little issues with Xcode 4 and ASOC.

No, you’re quite correct. But Apple’s history on these things is pretty clear: at some stage support for older versions gets dropped. With something as tied to the OS as Xcode, that’s probably going to happen sooner rather than later.

Shane,

Thank you for your templates fixing these annoying “details” in XCode 4.

I jumped into version 4 soon after having discovered XCode, so I have maybe less to regret, but I have the feeling that ASOC seems to be limited in time: there was really little noise about this bridge between AS and ObjC. But I hope that the structure of an ASOC program allows a relatively easy migration to Objective-C (or whatever C’s avatar that will come).

And hey, FORTRAN is still alive :lol:

Best regards,

Oh, I think it’ll be around for a while. One of the key things, I think, is that unlike AppleScript Studio, it’s a very low-maintenance technology. It’s built on the scripting bridge, which several other things rely on, and if anything, I suspect we’ll see its power increase.

But it also makes a perfect stepping stone to Objective-C.

Ahh. The good old days when there was no gui and life was simpler and you lived it on the command line :).

That’s what I would hope, especially considering all the time I’m investing in learning and rewriting code with ASOC, but with Xcode 4 offering less support than seen in Xcode 3, it makes me wonder if I should just take the plunge and jump straight to Obj-C. On one hand however, Xcode 4 seems like a pretty big upgrade from Xcode 3 so I wonder, if Apple just hasn’t gotten around to improving support for ASOC.

Xcode 4 is a work in progress. It reflects the priorities of the developer tools group, not necessarily Apple as a whole (if there is such a thing anymore).

If you’re writing apps that don’t involve any need for AS – that is, they don’t talk to other apps – there’s something to be said for going straight to Objective-C, although I think ASObjC is an excellent and comfortable transitional environment for someone who knows AS to gain an understanding of Cocoa and the frameworks, and how they work.

And a bit depends a bit on whether you want to make the next great, perfect app that’s going to make your fortune, or you want something that’s polished and does a job but doesn’t have to set the world on fire.

Where ASObjC really excels, of course, is where you want to put an interface on underlying AS.

It’s truly awful, it knows some words need to be different colours but it uses the Obj-C fonts and colours!!! Plus even worse it doesn’t understand the code enough to correctly put tabs in the lines.

It looks to me like the folks who worked on the ASOC portion of Xcode 3 haven’t been able to inject much code into the Xcode 4 base just yet. Here’s to hoping there’s a lot of good stuff “in the can”… Like maybe an ASOC version of the Drag-N-Drop from IB to source code that auto-creates outlets, actions, and bindings and the like (as demo’d back when Xcode 4 was first shown off a while back).

The key is demand; nothing will happen unless (lots of) people go to bugreporter and log requests.

I’ve been holding off on setting up Xcode 4, mainly because of the lack of ASOC support, but also because, for me, there’s a bit of a learning curve when it comes to the new layout (although I haven’t gotten around to watching any of the new WWDC session videos on it yet)…

Is this bugreporter accessed through a menu item in the app, or is there a web page for it (or both)? And, are they OK with general requests vs. actual bug reports there? I wouldn’t mind dropping suggestions to the right place, asking for things like:

¢ ASOC being included in “New File…”
¢ The ability to subClass ASOC classes.
¢ The ability to create Categories of existing classes.
¢ Generating the equivalent of @interface to avoid errors when calling ASOC classes (methods) from Obj-C code.
¢ Maybe the ability to create @protocol (or equivalent).
¢ Class methods along with Instance methods.
¢ (Previously mentioned) Drag-N-Drop from IB to source code that auto-creates, actions, and bindings and the like (even if it has “placeholders” like Xcode does now).

If it could do most/all of these, I’d be there in a minute.

Bugreporter is for those enrolled in Apple’s developer program. It’s at bugreporter.apple.com.

I’ve been doing some preliminary tests with your templates here, and I notice that along with the MyAppAppDelegatete.applescript file, there’s also created a pair of MyAppAppDelegate.h & .m files… When I go to compile and run, it barks about having two class files with the same name in there.

I see in the xib that there’s a blue cube with the name “My App App Delegate”, but it’s hard to tell right off which one it is… The Obj-C class or the AS class. A little testing would easily tell me (what I can bind to). [Edit: further tests looks like it’s the AS class in the xib/nib].

Did you perhaps intend for the .h/.m to not be included?

I don’t see that here, and I haven’t had any other reports of it.

My template is just a modified copy of the standard AS one, so I’m not sure how that could happen, although they are constructed in a cumulative way in Xcode 4. Have you modified any others yourself? What versions of Xcode and the OS are you running?

Haven’t modified anything here. Just a straight up Lion, then Xcode 4.1, then your template installer.

I’m guessing Lion is the key – the templates were written based on Xcode 4 under Snow Leopard.

I’ll have a look when I get back to Lion – thanks for the heads-up. Meanwhile, does just deleting the .h and .m files solve the problem?

Sure does.