[STUDIO] handlers w/o buttons?

I have two handlers I want called when the application starts. One will query various stuff and update buttons to reflect what is appropriate.

This works dandy if I have a button do it- but I can’t get it to run on its own when the app starts.
I’ve tried

on Launch 
  myhandler()
end Launch

and other things- but the problem is those seem to be run before the buttons are drawn on the application window.

I want the application window to come up all buttons unactive, then those that make sense to the users system and settings become active.

-=- The second thing I need to do is start a loop that updates a progress bar every 5 minutes.

I can’t attach that to a button as when a button is clicked, none others are available until the button’s action is finished.

This loop isn’t intended to ever finish- its a progress bar that monitors a task on the system that when finished, starts all over again.

Thus, the procedure or handler or whatever you want to call it needs to be started when the application is launched, again- after the window is drawn and active, and not interfere with the operations of the user buttons.

Any ideas on how to do this?

I’ve never seen a “launch” handler before. Is this something new, or something unique to AppleScript Studio, or have I had my head in the sand? :stuck_out_tongue:

I’d be inclined to try a run handler.

on run() 
-- gather the system info for the buttons and set them up 
end run

It sounds like you need an idle handler.

on idle 
-- update the stuff and create progress bar 
return 300 -- pause interval in seconds 
end idle

To use this, your script/application must stay open.

Does any of this make sense? It might be easier to offer assistance if you post some code.

– Rob J (who needs to consume more coffee before answering questions and who doesn’t have OS X)

AppleScript Studio does not have a RUN handler, and I believe he meant “launched” handler.

Michael, if you are using the latest AppleScript Studio, 1.8b3, then add an “awake from nib” handler. This reflects when you’re button is awaken from the nib, or when it is drawn.

Otherwise, you can add a ''will open" handler to your window. I usually find that it is best if you make it so that it is NOT visible at startup, then in the will open handler, do all your events, and then add a “set visible of theObject to true” or if you are using the latest AppleScript Studio, simply “show theObject”

Keep in mind that end users without the latest AppleScript Studio will not be able to use your app. It is also not available in 10.1.3, they have to specifically download the update. A fairly simple alternative is to use Cocoa’s awake from nib if you want it to be interoperable. But in this case, a will open handler will do.

Also, why are so many people using excessive handlers now? You do know you can have your code right in the handler itself? It was my understanding that handlers were for repetitve tasks (may be true for this particular statement… but I have seen lots of other overkill)

As for the idle handler, Rob, your code is correct (I am talking to both of you btw), but you must keep in mind that the idle handler is an event that NSApplication is sending out. So in your NIB file, select “File’s Owner” (this is the same as NSApplication) and check off the “idle” event. Then it should work accordingly.

Good luck!

I can’t speak for anyone else but I usually only use handlers for repetitive tasks unless, on occasion, when the script is long and a particular block of code is long, I’ll put it in a handler (at the end of the script) just for the sake of readability and organization. I may also have a handler ready to go for a certain task. If so, I’ll paste it in and move on to the next part of the script.

Thanks. When I move to OS X and AppleScript Studio, it’ll be like starting over. I can hardly wait! :stuck_out_tongue:

I am trying to make a dual purpose applet and droplet where a dalog opens if you double click it to find a file to operate on.

but if you drop a file on there, it skips the initial dialog and goes straight to the conversion:


on launched theObject
	set thefile to choose file with prompt "Choose a file..."
	converttoaco(thefile)
	quit
end launched

on open thefile
	 conversion(thefile)	
	  quit
end open

on conversion(thefile)
             black box conversion
end conversion


What do you think is the best way to accomplish this?

This is actually the purpose of a droplet :wink:

thanks for the hint: the solution was to use the default on idle instead of trying to hack in an on launched statement