Setting and saving properties between AppleScript files within Studio

Is it possible to set and save a value to properties of script files within an AppleScript Studio project? I am able to do this between regular AppleScripts. For example, I can create the following script and save it to the desktop or wherever:

on MakeScript(v)
	script
		property some_prop : v
	end script
end MakeScript

Then make another script with the following:

set f to choose file -- the compiled script
display dialog "Enter new text:" default answer "text"
set t to text returned of result
set s to load script f
set p to MakeScript(t) of s
store script p in f replacing yes

In this same script I can now access the content of the property ‘some_prop’ in my first saved script with:

set s to load script f
some_prop of s

And this works just fine outside Studio. The problem is that I can not get this scheme to work within my Studio project files. I am aware that Studio does not allow for property persistence between application activations, however, since Studio uses AppleScript files, I do not understand why I can’t implement the scheme shown above. There has to be a simple way to do this or Studio would be a seriously crippled environment for application development. Can anyone shine some light here?

Hi,

I use this in one of my projects
script #1

property scriptVersion : "1.0"

no explicit script object is needed

script #2

set s to ((path to me as text) & "Contents:Resources:Scripts:myScript.scpt") as alias
set t to load script s
set scVersion to scriptVersion of t

Thanks Stephen. Your example gave me faith and incidentally confirmed that it was not necessary to make a property assignment within a function. Yet the solution to my frustration turns out to be that you always have to reload your target script in order for the properties to register the change you sent it. In other words just because you stored and replaced target script B from script A doesn’t mean that a function within target script B will see the property assignment you made from A. Within the script B, you must reload the target script B (your self-same script file) to see the new property assignment sent by script A. I can not understand why this is so, but this is the way it works! :confused:

Are you talking about saving this value between completely separate ASStudio projects, or just between different script files within a single ASStudio project?

If you are in a single project, maybe you could write the value to the plist file for the project, then it could be loaded and modified in any script within that project. Might be easier and more consistent then trying to use properties the way you are using them.

Here is the main form that I use to write and read preferences in an ASStudio project. I guess this thread should really be moved over under the AppleScript Studio & XCode heading.

on launched theObject
	--Read in variables from the plist file
	readPrefs()
end launched

--Read in preferences from the Plist file. If no preference is there, it is created.
on readPrefs()
	if not (exists default entry "YourDataNameHere" of user defaults) then
		make new default entry at end of default entries of user defaults with properties {name:"YourDataNameHere", contents:VariableWithCurrentValue}
	else
		set VariableWithCurrentValue to contents of default entry "YourDataNameHere" of user defaults
	end if
end readPrefs

--Don't know what you want to trigger the change, this could be on click or whatever event you need
set contents of default entry "YourDataNameHere" of user defaults to VariableWithCurrentValue

Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)

Thanks Matt-boy for your suggestions. Note that despite the sour “facy” I posted on my last reply, I did find a solution–although somewhat strange–using the load and replace technique.

I am aware of the technique of writing to Studio’s preference object, however I need to transfer a moderately large set of data between tables in different nib files within the same project. Since this is not a preference setting, I hesitate to use the preference technique–tho perhaps I shouldn’t let the name scare me. In any case your sample code will be a future resource for me.

Thanks for tip about posting within Studio thread. I will post a reference from there to here.

Done.