Change properties of script object from outside the script

Even though I am actually using Applescript Studio, I believe that this question applies to vanilla Applescript, so here’s the code:


script openRecentItem
	
	property prevStopped : false
	property prevFinished : false
	
	on setStop(stopped)
		set prevStopped to stopped
	end setStop
	
	
	on setFinish(finished)
		set prevFinished to finished
	end setFinish
	
	
	on choose menu item theFile
		if not prevStopped and not prevFinished then
			-- do something
		else
			-- do something else
		end if
	end choose menu item
	
end script

Outside of openRecentItem I call with launching (running):


copy openRecentItem to gOpenRecentFile -- declared as a global property, initial value = null

In portions of the various other Handlers I will call


tell gOpenRecentFile to setStop(true)
tell gOpenRecentFile to setFinish(true)

Finally, when I open a file, I place its name in the “Open Recent” sub-menu and then set the script of this recent file to openRecentItem (or, gOpenRecentFile) via:


set script of recentFile to gOpenRecentFile

By the way, I have also tried the approach of deleting the copying of the script object to gOpenRecentFile and instead used:


set prevStopped of openRecentItem to stopped
set prevFinished of openRecentItem to finished

Net result with either the non-copying or the copying approach is that the 2 properties of the script object do not change.

This seems to work fine on its own:

global gOpenRecentItem

script openRecentItem
	property prevStopped : false
	property prevFinished : false
	
	on setStop(stopped)
		set prevStopped to stopped
	end setStop
	
	on setFinish(finished)
		set prevFinished to finished
	end setFinish
	
	on check()
		return {prevStopped, prevFinished}
	end check
end script

copy openRecentItem to gOpenRecentItem

tell gOpenRecentItem to setStop(true)

tell gOpenRecentItem to check()

You are absolutely correct … your Handler, check() does return the changed property values … but the “feature” that I haven’t yet found a solution for centers on:


on choose menu item theFile
		if not prevStopped and not prevFinished then
			beep
		else
			open {theFile} -- calls open theFiles Handler
		end if
end choose menu item

… which is activated by

set script of recentFile to gOpenRecentFile

If I test for either prevStopped or prevFinished inside the on choose Handler, I get false for both.

Now, here’s where I must crossover to Applescript Studio because the recentFile parm is an added menu item to the “Open Recent” sub-menu. I dunno, but maybe the problem centers on the sub-menu stuff, tho it’s hard to fathom why.

Even when I tested for the globals in the open Handler, both were false … so I suddenly remember somewhere on this BBS that whenever a script is assigned and later on used, that the property/global values are re-compiled … or something like that. This pertains to the lack of persistence of property variables in Applescript Studio apps whereas such persistence does currently exist in the Script Editor apps.

So, maybe I have to dig into the way Studio enacts persistence, i.e., via default entries (reference the Archive Maker app distributed with Studio). I was going to have to delve into this black hole anyway since I want the “Open Recent” files to persist from one run/launch to another.