Tuesday, October 23, 2018

#1 2018-08-03 05:27:33 am

technomorph
Member
Registered: 2017-12-14
Posts: 63

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?

Applescript:

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?

Applescript:

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

Applescript:

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

Offline

 

#2 2018-08-03 05:39:32 am

technomorph
Member
Registered: 2017-12-14
Posts: 63

Re: Script Object Variable Inheritance work thru Libraries as Well??

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?

Applescript:

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)

Applescript:



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

Offline

 

#3 2018-08-08 01:05:31 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 315

Re: Script Object Variable Inheritance work thru Libraries as Well??

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.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#4 2018-08-09 08:35:48 am

DJ Bazzie Wazzie
Member
From:: the Netherlands
Registered: 2004-10-20
Posts: 2807
Website

Re: Script Object Variable Inheritance work thru Libraries as Well??

technomorph wrote:

Within one script library can I reference another script library's variables?



Yes, if you mean properties with "script library's variables".

technomorph wrote:

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



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

Applescript:

property parent : script "parentScript"

technomorph wrote:

I've been reading that use of Globals is not very "good".



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

technomorph wrote:

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



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.

Applescript:

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.

Last edited by DJ Bazzie Wazzie (2018-08-09 08:37:43 am)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)