Applescript, cross reference the same information across multiple scripts.

I have 3 Scripts that I need to use independently of each other, yet they all share the same information.

Ideally I need to update that information so that i don't have to update 3 scripts.


How can I achieve this? One of the scripts is also a droplet.


This is the info I would need to access


property tightcut : ""
property shadowcut : ""

property brandTable : {¬
	{brandID:{"AP88"}, brandGroup:{"Apricot", 1500, 1500, true, false, "FFFFFF", tightcut, true, true, false, true}}, ¬
	{brandID:{"BA44"}, brandGroup:{"Banana", 1020, 1530, false, false, "F4F4F4", shadowcut, true, true, false, true}}, ¬
	{brandID:{"CA22", "CA84"}, brandGroup:{"Cabbage", 1196, 1300, true, false, "FFFFFF", tightcut, true, true, false, true}} ¬
		}



Currently I access it like this


set brandGroup to my get_brandGroup(brandTable, missing value, brandID)


Posted on Jan 28, 2019 8:53 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 29, 2019 2:33 AM

Use a script library and load it at runtime.


A script library is nothing more than a standard compiled AppleScript - it can be exactly as you've written above.


Then in your other scripts you load the library at runtime:


set myLib to load script file "path:to:your.scpt"


Now you can reference properties and handlers in your library by targeting it:


set brandGroup to myLib's brandTable


3 replies
Question marked as Top-ranking reply

Jan 29, 2019 2:33 AM in response to MattJayC

Use a script library and load it at runtime.


A script library is nothing more than a standard compiled AppleScript - it can be exactly as you've written above.


Then in your other scripts you load the library at runtime:


set myLib to load script file "path:to:your.scpt"


Now you can reference properties and handlers in your library by targeting it:


set brandGroup to myLib's brandTable


Jan 29, 2019 4:12 PM in response to MattJayC

Here is an example that I've gotten to work.


My so called a.app.

on run
	set myApp to "/Applications/applescriptFiles/demo -- the best/b.app"
	-- some hocus pocus is nesessary to avoid applescript from change path.
	
	
	tell application myApp	
		launch
		stringSet("stringie set") -- this function is in the "b" app.
	end tell
end run



My so called "b.app".


(* 

save this as an application bundle 

invoked by a.app.  

twtwtw write in:
https://discussions.apple.com/thread/4917321?start=15&tstart=0

hocus-pocus: 
 
Give your script application a unique bundle id string (CFBundleIdentifier) 
and a unique bundle name (CFBundleName) too, to make life easier.  
You set those in the info.plist file.  Launch the script app once to register 
it with launch services, and system will be able to find it thereafter.

Example:
      <key>CFBundleIdentifier</key>
      <string>com.rccharles.b</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>b</string>
	
	I added the CFBundleIdentifier info above the CFBundleInfoDictionaryVersion line.
 I left the CFBundleInfoDictionaryVersion and CFBundleName as is.

	
	*)

property myVar : "initial value"

on run
	display dialog myVar
end run

on stringSet(inputVar)
	set myVar to inputVar
	display dialog "variable myVar is " & myVar
end stringSet

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript, cross reference the same information across multiple scripts.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.