Transition from Script Editor to XCode

I’ve decided to make the jump from Script Editor to XCode. I’m hoping the problem I’m running into is a common Applescript Xcode first timer mistake…

I started a new Applescript droplet project in XCode. All I need in this project is a simple Menu, idle loop, and drop support. Eventually, I’ll add dialogs, so I need to keep nib support available.

I pasted in my source, added my resources, and changed my “on run” statment to an “on launched”. OK, so far so good. Compiles fine. Icon, and all the info.plist items look correct. Fire it up and… nothing. It appears to be running, but by all my tests, none of my event handlers are getting called. The “on launched” handler is never called, and if I change that to “on will launch” or “on awake from nib” I get the same result… they never get called.

There has to be some mind-numbingly simple mistake I am making, but i don’t see it. I’ve looked at Studio examples like the countdown timer, and it has essentially the same structure as mine, so what gives?

Frustrating since I have built a fair number of XCode C projects without any problems.

MoonlightMac - DVD Assist for Front Row

Did you bind everything in Interface Builder? I don’t think that xcode apps can really ‘do’ anything without that interface…

But I’m no expert. There are people here far better qualified than I to say anything about this :stuck_out_tongue:

While I know what Parrothead3’s trying to suggest here, it may be a bit misleading because “Bind” isn’t really the right word. To bind, would probably suggest using “Bindings” which is NOT what you need to do. A more appropriate word would probably be “Connect”.

Here’s a better explanation…
In Interface Builder (IB), you’re probably familiar with the “Nib” window (probably titled “MainMenu.nib”), and the “Inspector” window (“Tools > Show Inspector”), where you can configure many of an objects settings. In the “Instances” pane of the Nib window, you’ll see icons which represent all of the instantiated views, controllers, etc. You’ll see your windows, menus, views, and so on. One of these is going to be the “File’s Owner” icon. This is a representation of your NSApplication object… i.e. your app. Click on it, then go over to the Inspector window. From the pull-down menu, select the “Applescript” pane. Here’s where you’ll find all of the handlers that you can connect to your application. One of the options will be the “launched” handler, listed under “Application”. Check the box next to it, select your script in the matrix below, then click the “Edit” button. You’ll then be taken to your script where you can edit the handler to write code for your new connection.

A common mistake is simply cutting and pasting code from wherever into your project and thinking that it’s presence alone will make it magically work. You need to make connections in IB between every object and the handlers in your code that you want the object to respond to. Note, also, that you don’t have to provide the handlers themselves when you create a connection. When you connect an object to a handler in IB, then click the 'Edit" button, an empty handler is created for you in your script. If the handler already exists, then it is connected to that preexisting handler. You can then add in all of the code that evaluates the object sending the action. Oftentimes, trying to write handlers by hand or using handlers you’ve pillaged from somewhere else, can lead to typos or mislabeling, and can be hard to track down when your code fails.

Good luck, and let us know if that didn’t help.

Many, many thanks. When creating a drop applet, it only enables idle and open in the nib connections. Makes sense.

Ticked off “Launched” and it is working as expected.

Thanks again!