How to call a "Launched" event in ASOC???

In AppleScript Studio I used to write apps that executed code right away, without clicking any buttons…

I used the “Launched” event.

How do I write the same in ASOC??

I tried this:

on applicationDidFinishLaunching(aNotification)
say “here”
my showStatus_(sender)
my updateStatusMessage_(“Loading app…”)
delay 3
my HideStatus_(sender)
end applicationDidFinishLaunching

But it doesn’t work. I guess I need to call a “Launched” event, and not a did finish launching.

Where can I find some documentation to read? doesn’t have much…


applicationDidFinishLaunching(aNotification) needs an underscore in it:



Thanks Ric.

But it still doesn’t work for me.

It has be “Launched” I guess.

How do I call the event “Launched”??

Try applicationWillFinishLaunching_(aNotification)


No, it doesn’t. Either applicationWillFinishLaunching_(aNotification) or applicationDidFinishLaunching_(aNotification) should work. Where do you have this method? Is it in your app delegate?


I need to start a progress bar as soon as the app is launched, and display info for the user on a text field, so he/she knows the app is not stuck or dead.

Mainly I will be reading data from a Filemaker db and do text manipulation, compile a file and sign it. In the process I will update the status message some 20 times.

The app should run automatically on launch, without the user clicking a button.

Note that I have put a “say” in my example, and I don’t hear the frase as the app is launched, nor the progress bar or window is displayed.

When I see the window, the progress bar is visible (shouldn’t be, once I call “my HideStatus_(sender)”). I guess my code is not being executed.

How is this done in ASOC?

Can you post me an example?

Are you using Xcode4? The reason I ask is because in Xcode3 there is a template for applescriptObjectiveC projects that gives you a script with the applicationWillFinishLaunching: method already in place, and this script is the app delegate, so it can respond to that method ( applicationWillFinishLaunching: is a delegate method in the NSApplicationDelegate Protocol).

So, if you are using Xcode4, I’m not sure what you get when you start a project since I haven’t used it. Someone who is using Xcode4 would be better to instruct you on how to set up your project so that applicationWillFinishLaunching: will run correctly.

I think there are several other problems with the code you posted. You probably don’t need to have the “my” in front of your statements (though it’s hard to tell, since I’m not sure what you are doing). You shouldn’t really use the delay command in ASOC, it just locks up your interface for 3 seconds. Your showStatus: and hideStatus: methods shouldn’t have sender as an argument because it won’t be defined (you usually use “sender” for methods that are called by buttons or text fields or other UI elements, not methods that you are calling from the code).


You get the same as in Xcode 3 – the applicationWillFinishLaunching_(aNotification) handler is already there.


I thought you said in a previous post that there is no template for an AppleScriptObjC class file, and that you had to do everything manually. Is this not true?


There’s no template for when you want to add a new class file to a project; there is an app delegate template, the same as Xcode 3.

Dear friends,

Please help.

Why doesn’t this simple code work?

on applicationDidFinishLaunching_(aNotification)
say “here”
display dialog “Hello World!”
end applicationDidFinishLaunching_


We’d love to help – the problem for us is that that code does work. Try starting a new project and see what happens.

The code does work – if I paste it into a new app, it works fine. The only thing that I can think of is that your script is not the app delegate. If starting a new project as Shane suggests, doesn’t work, send me a copy of your app and I’ll see if I can figure out what is going on.


I have 2 files that were given to me by a more experienced programmer, to make sure my app stays always frontmost all windows.

The files are:

// appDelegateAppDelegate.h
// appDelegate
// Created by Joby Abraham on 09/02/11.
// Copyright 2011 MyCompanyName. All rights reserved.

#import <Cocoa/Cocoa.h>

@interface appDelegateAppDelegate : NSObject
NSWindow *window;

@property (assign) IBOutlet NSWindow *window;


=== And:

// appDelegateAppDelegate.m
// appDelegate
// Created by Joby Abraham on 09/02/11.
// Copyright 2011 MyCompanyName. All rights reserved.

#import “appDelegateAppDelegate.h”

@implementation appDelegateAppDelegate

@synthesize window;

-(void) awakeFromNib
[[NSApplication sharedApplication] setDelegate:self];

  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification

-(void) applicationDidResignActive:(NSNotification*) notification
[window setLevel:NSFloatingWindowLevel];


=== end files

Can these two files be the cause?

I did not understand yet the meaning of a delegate, would someone be so kind to explain or point me to links to study?

I appreciate your kindness.

Yes. Only one object can be the application’s delegate; it looks like you have an Objective-C one and an AS one.

A delegate is an object that gets sent certain messages when something happens with the object it’s a delegate to. In this case, the application delegate gets sent messages when the application launches, and so on.

If it were me I would get the Obj-C code to send a message to your ASOC script when the app launches. But I’ve never talked between languages before, ask these guys :slight_smile:

Now I take a second look… If those are the entire files you should just convert that stuff into AS. I think all you need is:

property parent: class "NSObject" of current application

property window: missing value --IB link this to the window

on applicationDidFinishLaunching_(aNotification)
    say "here"
    display dialog "Hello World!"
end applicationDidFinishLaunching_

    --window's setLevel_(--???) haven't a clue how to get NSFloatingWindowLevel in ASOC since it hasn't been assigned an integer
end applicationDidResignActive_

But that’s what you put in the delegate anyway.

Hello my friends,

Thanks for being so patient.

This is my problem, I explain so you can understand…

I have some AppleScript Studio apps that have as many as 5,000 lines of code.

Since Lion will no longer support AppleScript Studio for building apps, I have made up my mind to finally migrate all of my code to ASOC.

These apps interact with Filemaker Databases, basically it reads fields and creates a large chunck of text, write in disk and sign it using a certificate.

In order to make the app user friendly I would like the window to stay floating, so I have already solved that using the code I meantioned. Other wise the user might click another window and my app’s main window stay behind and the user won’t know the app is running.

I would like also the app to be executed right away from launch, without the need to click on a button or anything.

I have uploaded to my iDisk this example, that works if I click on a button and doesn’t work if I leave the code to be executed on applicationDidFinishLauching_

I would be very gratefull if someone can point me to how I can do a progress bar running on Launch…


This is where you can download it:


I downloaded your code and everything works. It sounds like you want to start the progress bar at launch, not at the press of a button. Here’s how:

property theStatusBar : missing value

on applicationWillFinishLaunching_(aNotification)
theStatusBar 's startAnimation_(me)
end applicationWillFinishLaunching_

You could also use applicationDidFinishLaunching.

Hope this helps!


Did you get rid of the two objective C files? And if so, do you now get the beeps and the saying of “here”? If you are not getting these, then there is something still wrong with the overall structure of your app, it’s not a problem with the applicationDidFinishLaunching method.

On the other hand, if you are getting the beeps, then it isn’t working because of what I told you in an earlier post – you shouldn’t have “sender” as the argument for a method that is called by code instead of a button. In your applicationDidFinishLaunching method, you have two calls to your own methods, showStatus_(sender) and hideStatus_(sender) --These won’t work because “sender” is undefined! If you run your app with the console window open, you should see an error message to that effect. It works when you click the button, because “sender” is now the button that you clicked, so everything works as it should. However, there is really no need to have any arguments for these methods since you don’t use any in their implementation – the methods should just be showStatus() and hideStatus().

Also, in the startAnimation: and stopAnimation: methods you should use “me” as the argument rather than sender.

One more thing, the line “tell me to activate” is unnecessary.

Your code should look like this:

script ProgAppDelegate
	property parent : class "NSObject"
	property progress_field_01 : missing value
	property progressBar_01 : missing value
	property button_test_progress_bar_01 : missing value
	on applicationDidFinishLaunching_(aNotification)
		beep 3
		say "here!"
		updateStatusMessage_("Loading app...")
		delay 3
		updateStatusMessage_("App has loaded...")
		delay 1
	end applicationDidFinishLaunching_
	on testProgressBar_(sender)
		beep 1
		updateStatusMessage_("Testing 1...")
		delay 1
		updateStatusMessage_("testing 2...")
		say "done"
	end testProgressBar_
	on showStatus()
		progress_field_01's setHidden_(false)
		progressBar_01's setHidden_(false)
		progressBar_01's startAnimation_(me)
	end showStatus
	on HideStatus()
		(**** User friendly: ****)
		delay 0.5
		progress_field_01's setStringValue_("")
		progress_field_01's setHidden_(true)
		-- set my incrementBarreProgress to i as  integer
		progressBar_01's stopAnimation_(me)
		progressBar_01's setHidden_(true)
	end HideStatus
	on updateStatusMessage_(theMessage)
		(*** atualizando a mensagem: ****)
		progress_field_01's setStringValue_(theMessage)
	end updateStatusMessage_
end script

This will work, but it’s still not ideal because of the delay statements – they will lock up your interface and shouldn’t be used in ASOC. It would be better to use NSTimers or performSelector:withObject:afterDelay: to control your timing, but that’s a topic for another post.


Thanks to all my dear friends, Shane, Richard, rdelmar and thewaytoapplescript.

I am back on scripting, at least I hope so.

The biggest problem for me is that I am going thru a great transition:

Going from Snow Leopard to Lion
Going from xCode 3.2 to xCode 4.2
Going from AS Studio to ASOC

I couldn’t find where my products were being built, and xCode 4.2 behaves completely different from xCode 3.2.

Hiting the button “build” does not show you how your app is going to behave in the real world, it just compiles the app and runs your code.

In my case, I did not see my main window, or progress bar, and so I thought my code was not functional.

In order to see how your app behaves I had to go:

Product → Build for → Build for archiving

Then take a look at the final product running, and then it ran the way I wanted.

I am not sure, if this is a feature or a bug, but anyway it has been a great struggle to understand this.

I hope this post helps other programmers,

Take care, thanks guys, you were really nice to me.