"on launch" - how?

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?


Hi Roland,

try this

property init : true

on open 
	if init then initialize()
	set init to false
	-- go on
end open

on quit
	set init to true
	continue quit
end quit

That’s exactly what I’m doing now but it seems like such a tenuous hack! :slight_smile:

I guess I should just chalk it up to another AppleScript oddity… at least odd to me. :slight_smile:

see your other thread for a suggestion though it itself is a hack/workaround :smiley:

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!!! :slight_smile:

for example, why does my custom icon disappear from my AppleScript “after a while” very very odd!

Hi Roland,

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