Faster applets, that doesn't store properties not stored explicitly

Hello!

This is just an experiment, but it works as it should, no matter what you do, you will not be able to store any properties, unless you explicitly write the properties to disk, and reads them back in.

The approach in the code, is also proven to execute less appleevents, as the the events will be routed from the applet to the StandardAdditions.osax which from then onwards will send and retrieve apple events with any applications targeted.

All in all a pleasant model for making applets! :slight_smile: I have added a handler for opening stuff as well, to show that it works for droplets as well. This is meant for a run and die applet, but I think it should be equally easily to adapt the concept for a stay open applet, with a runhandler, just returning the idletime. which is then returned by the on idle handler in the applet.

The construct would be something like this:


on idle
    return run script idleScript with parameters {theStuff's whatever}
end idle

The idleScript would then also have theStuff as its parent, in order to share data during run-time, which will evaporate when the applet quits. :slight_smile:

I challenge you to try to make the applet quit, and display a value of a higher than 0 when showing the dialog! :slight_smile:
(Retaining the script construct within of course!)


-- property parent : AppleScript
property toplevel : me
property a : missing value

script theStuff
	-- property parent : AppleScript -- not necessary 
	--	property a : missing value
	to reader()
		--global a
		tell me
			activate
			display dialog "this is A : " & a
		end tell
	end reader
	
	to writer()
		-- global a
		try
			set a to a + 1
		on error
			set a to 0
		end try
	end writer
end script

script babyStuff
	property parent : theStuff
	on run
		writer()
		reader()
		tell toplevel to quit
	end run
end script

script biggerStuff
	property parent : theStuff
	on run {what}
		writer()
		reader()
		tell me
			activate
			display dialog ("ouch! you dropped " & item 1 of what as text) & " on me! a is : " & a
		end tell
		tell toplevel to quit
	end run
end script

on run
	-- global a -- wherever you want, it won't get saved.
	run script babyStuff
end run

on open theItems
	run script biggerStuff with parameters {theItems}
end open

on quit
	continue quit
end quit