Script Object Variable Inheritance work thru Libraries as Well??

I’m guessing the Script Libraries are essentially Script Objects themselves?

Question 1) Within one script library can I reference another script library’s variables?

script LibA
property X : "apples"
property Y : "oranges"

script LibB
property parent : LibA
property W : "lemons"
property Z : "limes"

Question 2) How about a script object within a script library?

script LibC
property zz : {} -- for inheritance???

script D
property parent :zz
property X : "apples"
property Y : "oranges"
end script

script E
property parent : zz
property W : "lemons"
property Z : "limes"
end script

------the other library

script LibF

property parent : LibC  -- guess will only give me access to property zz?
--or 
property parent : D -- will that actually go straight to the D object or do I need the following?

property parent : LibC's D
property parent : LibC's E

when I think about this I can’t see why I would need to access the subscripts of a separate Library
but would be great to access some top level Variables from other script library’s

thanks

Kerry

Also this is the data that I want to be able to share.
I’ve been reading that use of Globals is not very “good”.

Is there a better way for me to “share” this between libs? should I create them in my main script?

property allattALBUM : {"title", "TRACK", "OF_TRACKS"}
property allattCUEV2 : {"NAME", "DISPL_ORDER", "TYPE", "START", "LEN", "REPEATS", "HOTCUE"}
property allattENTRY : {"title", "ARTIST", "AUDIO_ID", "LOCK", "LOCK_MODIFICATION_TIME", "MODIFIED_DATE", "MODIFIED_TIME"}
property allattENTRYINDEX : {"ENTRYNO_xx"}
property allattINFO : {"BITRATE", "CATALOG_NO", "COMMENT", "COVERARTID", "FILESIZE", "FLAGS", "GENRE", "IMPORT_DATE", "KEY", "KEY_LYRICS", "LABEL", "LAST_PLAYED", "MIX", "PLAYCOUNT", "PLAYTIME", "PLAYTIME_FLOAT", "RANKING", "RELEASE_DATE", "REMIXER"}
property allattLOCATION : {"VOLUME", "DIR", "FILE", "VOLUMEID"}
property allattLOUDNESS : {"ANALYZED_DB", "PEAK_DB", "PERCEIVED_DB"}
property allattMODINFO : {"AUTHOR_TYPE"}
property allattMUSICALKEY : {"VALUE"}
property allattPRIMARYKEY : {"KEY", "TYPE"}
property allattTEMPO : {"BPM", "BPM_QUALITY", "BPM_TRANSIENTCOHERENCE"}

property alltheNODES : {"ALBUM", "CUE_V2", "ENTRY", "ENTRYINDEX", "INFO", "location", "LOUDNESS", "MODIFICATION_INFO", "MUSICAL_KEY", "PRIMARYKEY", "TEMPO"}
property allPROPERTIES : {allattALBUM, allattCUEV2, allattENTRY, allattENTRYINDEX, allattINFO, allattLOCATION, allattLOUDNESS, allattMODINFO, allattMUSICALKEY, allattPRIMARYKEY, allattTEMPO}


one thought I have would be to do this: (the main ones I need a alltheNODES and allPROPERTIES)



property alltheNODES : {"ALBUM", "CUE_V2", "ENTRY", "ENTRYINDEX", "INFO", "location", "LOUDNESS", "MODIFICATION_INFO", "MUSICAL_KEY", "PRIMARYKEY", "TEMPO"}
property allPROPERTIES : {}

set allattALBUM to {"title", "TRACK", "OF_TRACKS"}
set allattCUEV2 to {"NAME", "DISPL_ORDER", "TYPE", "START", "LEN", "REPEATS", "HOTCUE"}
set allattENTRY to {"title", "ARTIST", "AUDIO_ID", "LOCK", "LOCK_MODIFICATION_TIME", "MODIFIED_DATE", "MODIFIED_TIME"}
set allattENTRYINDEX to {"ENTRYNO_xx"}
set allattINFO to {"BITRATE", "CATALOG_NO", "COMMENT", "COVERARTID", "FILESIZE", "FLAGS", "GENRE", "IMPORT_DATE", "KEY", "KEY_LYRICS", "LABEL", "LAST_PLAYED", "MIX", "PLAYCOUNT", "PLAYTIME", "PLAYTIME_FLOAT", "RANKING", "RELEASE_DATE", "REMIXER"}
set allattLOCATION to {"VOLUME", "DIR", "FILE", "VOLUMEID"}
set allattLOUDNESS to {"ANALYZED_DB", "PEAK_DB", "PERCEIVED_DB"}
set allattMODINFO to {"AUTHOR_TYPE"}
set allattMUSICALKEY to {"VALUE"}
set allattPRIMARYKEY to {"KEY", "TYPE"}
set allattTEMPO to {"BPM", "BPM_QUALITY", "BPM_TRANSIENTCOHERENCE"}

set allPROPERTIES to {allattALBUM, allattCUEV2, allattENTRY, allattENTRYINDEX, allattINFO, allattLOCATION, allattLOUDNESS, allattMODINFO, allattMUSICALKEY, allattPRIMARYKEY, allattTEMPO}


thanks

I don’t know the specific answers to your question about sharing variable values between scripts, but to the best of my (limited) knowledge, it’s not possible with Applescript.

However, I do share data between scripts sometimes. I just have the scripts save/read a plain text file to a library directory where both scripts look. I use JSON (ASObjC can convert back and forth between AS records and JSON), but you could use XML, property lists, etc.

Yes, if you mean properties with “script library’s variables”.

Your question doesn’t really match you’re example so here is my answer based on your example code:

property parent : script "parentScript"

That’s correct. I won’t get into much detail but in programming data should have proper ownership and globals doesn’t have this.

As with the global problem you should have one library who’s owner of the data and you should allow other libraries get and set the data through getters and setters.

property __myData : missing value

on setString(_str)
	-- Data validation needed here?
	set __myData to _str
	-- Do something here if needed, like notifications.
	return true -- if successful 
end setString

on getString()
	return __myData
end getString

While it may seem much more easier to directly change property values and behaves exactly the same, it’s much safer this way in terms of making programming mistake. There is no mistake of ownership, other libraries works with copies and can’t accidentally erase the data of your library. If it needs to be altered you can send data to this object’s setter and the object itself will handle the update.

A more general note on this subject: Normal OO programming languages works with classes and objects (instances of classes). AppleScript is like JavaScript prototype based which means you always work with instances and classes don’t exists. Script Libraries are just like any other script object like you would load from load script command for example or create an copy. So everything you can do with an normal script object you can also do with an Script Library. The only real difference between this and script libraries is that it makes sure it’s loaded only once and it allows other writing styles.