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.
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.
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!
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?