Defining variable in a loaded script

Is there a way to load a script into the current script and redefine a variable (set as a property) in the original script? I know the variable could be passed to whatever the subroutine was, but what if the original script is not set up as “on Subroutine (variable)”? What if it’s just “on Subroutine ()” but you still need to define a variable in that subroutine? Here is a very scaled down example which hopefully will explain what I mean…

set commandLib to load script file ((path to home folder as string) & "Documents:Custom Scripts:Print_QuarkDocs_Main.app")
tell commandLib
	set RegMarks to the button returned of (display dialog "Registration marks?" buttons {"Yes", "No", "Cancel"}) as text
	print_PDF()
end tell

In the script “Print_QuarkDocs_Main.app”:

property RegMarks : ""
on print_PDF()
--do the print part using variable RegMarks
end print_PDF

In this example, the property RegMarks would keep whatever value it had in the original script.

Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
AppleScript: Tiger
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

If you really want to do it that way, then you can use store script:

set scriptFile to alias ((path to home folder as Unicode text) & "Documents:Custom Scripts:Print_QuarkDocs_Main.app")
set commandLib to load script scriptFile
display dialog "Registration marks?" buttons {"Cancel", "No", "Yes"}

tell commandLib
	set it's RegMarks to button returned of result
	print_PDF()
end tell

store script commandLib in scriptFile replacing yes

I tested it with this:

property RegMarks : ""

on print_PDF()
	display dialog "RegMarks is set to: " & RegMarks buttons {"OK"} default button 1
end print_PDF

I think you answered more than I needed! I didn’t need to store the property value back to the original file, I just needed to get the variable to pass to the stored script. Looks like all I needed was to add “it’s” and now it works. The store script command is interesting though. I may need that later…

Thanks a lot for your help. This will allow me to have one Quark print script that I can load up in other scripts that need a printing step. Very cool.

Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
AppleScript: Tiger
Browser: Safari 419.3
Operating System: Mac OS X (10.4)