On run and On Open in ASS

I’ve got an AppleScript Studio project that currently centers around an on open handler, but I’d like to include an on run handler for instances where people double-click the app instead of dropping something on to it. Though I’ve done this before using AppleScript without ASS, I can’t get it to work now - the on Run handler never seems to get triggered. Is this just me?

I couldn’t find a “run” handler in the AppleScript Studio Terminology Reference or in IB. I don’t think it is available to ASS (or needed for that matter). Read the section in the Terminology Reference about “awake from nib.” This lists the handlers are that are called at application start-up and the order that they are called in.

Hope this helps,
Brad Bumgarner, CTA

As Brad says, there is no run handler for applescript studio projects. Depending on the goal you’re after, there may be methods of performing actions in a studio app that are similar in function. First, take a look at the application (file’s owner) ‘activated’ handler. It gets called any time the application is not the frontmost process and then becomes it. A click on a dock icon or icon in the finder would trigger the activated handler, as would a specific call to the app to “activate” by another script or process. Unfortunately, if the application is already active, clicking on it produces nothing, and cannot be detected as far as I know. A workaround I’ve found to this is by accepting the activated handler in your code, doing whatever it is you want to do, and then making some other application the active app. This way, you can generally be assured that any click on the app icon will be a fresh activation. This can be ugly though, and your code must be solid or it will be unpredictable. I used it in a prototype for a ‘dockling’ which popped up a window when the dock icon was clicked. It get’s very complex trying to make sure that whenever your actions are done, that the app is no longer active and is ready to become activated again. I don’t recommend it, only mention it as a possibility.

In the case of double-clicking on the app icon, this is only effective as a means of activating the app, not of making it perform an action. The second click is ignored. There is no separate handler like run or “on double clicked” that can catch an event like this.

As Brad also said, I’m not sure that this is a feature that is necessarily desirable in an asstudio app. The whole “purpose” behind asstudio is to develop interfaces for scripts so you can get AWAY from the limitations of plain applescript. Taking the method of activation away from the icon and putting it into a graphical interface is much more graceful and feature-rich, although not as “easy” as your double-click-able script. If having windows or menu’s is not of interest to you as the primary method of accessing your code, then asstudio projects probably aren’t for you. If using asstudio is necessary for you, consider designing your interface to add the functionality you want using the protocols available to you. Otherwise, you’ll eventually end up back using plain scripts.

Perhaps you could provide us some insight into what exactly you’re trying to do. Double-clicking on an application’s icon is a VERY counter-intuitive thing to do, given that it is not typically seen in actual “applications”. Maybe there are other options you have not considered that we could help you with.

Let us know…


I’m not sure I understand what you mean by the above … I double-click on an app’s icon to launch it all the time. Am I not reading your statement correctly?

Brad Bumgarner, CTA

:rolleyes: All right, I got carried away with my comment… making assumptions about the whole setup without thinking about it.

You’re right Brad, double-clicking on the icon will both launch and activate it, and will activate it at any time when accessed from the finder. Where I got carried away was with evaluating how the app would respond when activated using the DOCK. I tend to navigate to apps using other methods, so I RARELY double click on an icon to activate the app. I use launchers, the dock, or other means to activate apps, so making an app respond to the activated handler was kind of foriegn to me.

Honestly, the only place I can see having an app practically use double-click activation would be on the desktop. Most people shy away from storing their apps on the desktop though, no matter how useful they are. I would hate to have to navigate through the file system to find apps at painfully difficult-to-access paths… even an app in the applications directory for that matter… just to make it do something. That is why apps have menus, windows, and an icon in the finder, so we can use their functionality without having to find them on the HD every time we want to actually use them.

So, Brad is right… if using the finder… then the ‘activated’ handler is the closest thing to the run handler. Note though, that there is mixed support for activating it from the dock and many app launchers, so people like me who will NEVER ONCE double click on the app’s icon need some other mechanism for getting at the meat and potatoes of your app.

Sorry to jump to conclusions and cause confusion… both to Brad and benlong. Benlong, let me know if you need any more confusing advice. :wink:


I’m a dork, I admit it! :wink: I JUST found out that I DON’T have to double-click apps in the sidebar!

I DO keep my primary apps on the dock, as well as 1 or 2 on the sidebar. I keep aliases of my “secondary” apps in my Favorites folder and THOSE I double-click to launch.

Benlong, I hope that our discussion hasn’t totally confused you.

Jobu, I always look forward to reading your comments. I have learned a tremendous amount from your advice. Keep up the great work.

Brad Bumgarner, CTA

Hi all,

Thanks for all your help. Awake from nib worked just fine for trapping the things that I needed to trap.

And no, Brad, the conversation wasn’t confusing, and I very much enjoyed watching the discussion progress.

Thanks again