I have a “stay open” application script that has initialization code that needs to be called ONCE and only once. The script is launched when files are dragged to it. The script stays open. More files can be dragged while the script is still open. Since both of these events (initial and subsequent dragging of files) call the “on open” handler, and due to the persistence of globals and properties, I have no way of knowing when the “first” call to “on open” is happening. Is there something like an “on launch” event that could be used for one-time initialization?
property init : true
if init then initialize()
set init to false
-- go on
set init to true
That’s exactly what I’m doing now but it seems like such a tenuous hack!
I guess I should just chalk it up to another AppleScript oddity… at least odd to me.
see your other thread for a suggestion though it itself is a hack/workaround
Yep, I had three threads going, sorry about that. I thought perhaps I asked the question in the wrong way initially. And also thanks for your answer on the Apple Forums! I’m still trying to figure out the best place to ask AS questions, I typically come up with some oddball problems that people tend to ignore!!!
for example, why does my custom icon disappear from my AppleScript “after a while” very very odd!
I was thinking about doing somehting with script objects, but a much easier way is create another subroutine with parameters and pass different parameters from your idle handler and open handler. e.g.
set start_time to (current date)
on open these_files
set cur_date to (current date)
display dialog (p as string)