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?
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!!!
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.
global start_time
--
on run
set start_time to (current date)
end run
--
on idle
DoSomething(start_time)
return 2
end idle
--
on open these_files
set cur_date to (current date)
DoSomething(cur_date)
end open
--
on DoSomething(p)
try
display dialog (p as string)
on error
quit
end try
return
end DoSomething