Question
So What the heck is AdobeLibrary2.jsx?
So far I've written a bit about what's in AdobeLibrary1.jsx and AdobeLibrary3.jsx. Now it's AdobeLibrary2.jsx's turn.
Bridge provides one method for persistently storing script settings. app.preferences is how it's done. But what if you want to store a bunch of stuff, and you don't want it destroyed when the user purges their preferences?
For example, the import from camera script stores standard import locations and renaming templates. You don't want your user to lose those things if the trash their Bridge preferences.
The answer is ScriptStore - AdobeLibrary2.jsx
ScriptStore is an XML storage facility. It's primitive in that there is very little searching capability, you have to know what you put in there. But it's also robust and fast.
The actual data is stored in a folder in the user data area
Win: c:\documents and settings\[user]\application data\adobe\ScriptStore
Mac: [user]\library\application support\adobe\ScriptStore
There are plenty of examples in Import from Camera on how to use it.
But the basics are (and most of this is in the top commented section of the library itself):
MyScript = {};
MyScript.store = ScriptStore.open( "$$$AStoragePalceForMyScript" );
ScriptStore.open - will launch ScriptStore, and open a "store" with the given name. The name can not contain spaces, and must be unique from all other store names. So use something goofy. If the store does not exist, it returns a new, empty store.
To put simple data into the store:
store.put( type, name, value );
Where type is a string - just a name - allows you to store more than one property of the same name, but delineating a "type" or category of data.
name is the name to store it under
value is the value
store.put( "metadata", "Fred", "Flinstone" );
This creates an xml structure like:
<metadata>
Flintstone
Doing it again:
store.put( "metadata", "Barney", "Rubble" );
yields:
<metadata>
Flintstone
Rubble
Attempting to overwrite does exactly that.
store.put( "metadata", "Barney", "Fife" );
yields:
<metadata>
Flintstone
Fife
To get stored data:
store.get( "metadata", "Barney" );
returns "Fife"
You can also put Arrays into storage:
var ar = ["Fred","Barney","Wilma","Betty"]
store.putArray( "metadata", "FlintstoneAdults", ar );
and get arrays
store.getArray( "metadata", "FlintstoneAdults" );
In AdobeLibrary1, we created an object definition, Hashtable - which I find uniquely useful.
You can:
var ht = new Hashtable();
ht.put( "Fred", "Flintsone" );
ht.put( "Barny", "Rubble" );
ht.put( "Wilma", "Flintstone" );
ht.put( "Betty", "Rubble" );
store.putCollection( "metadata", "FlintFolk", ht );
and
var ht = store.getCollection( "metadata", "FlintFolk" );
And if these put and get methods aren't enough for you, you can create your own data structure and traverse it yourself.
store.root is the root XmlNode of the store.
So to make your own structure, use XmlNode.addNode( name, value );
myNode = store.root.addNode( "myNode" );
myDataNode = myNode.addNode( "Fred", "Flintstone" );
this creates an XML structure:
Flintstone
Once you have stored this sturcture with: store.save();
You find it this way:
var MyNode = store.root.findNode( "myNode" );
var Fred = myNode.findNode( "Fred" ).getValue();
You can find a node among multiple nodes:
store.findNode( name, count );
where count is an integer. Count = 0, it finds the first instance of a node with "name". Count = 1, it finds the second.
Or you can just get them all:
store.findNodes( name ); which returns a array of nodes
I hope you all find this as useful as I do.
Bob
Adobe Workflow Scripting
Bridge provides one method for persistently storing script settings. app.preferences is how it's done. But what if you want to store a bunch of stuff, and you don't want it destroyed when the user purges their preferences?
For example, the import from camera script stores standard import locations and renaming templates. You don't want your user to lose those things if the trash their Bridge preferences.
The answer is ScriptStore - AdobeLibrary2.jsx
ScriptStore is an XML storage facility. It's primitive in that there is very little searching capability, you have to know what you put in there. But it's also robust and fast.
The actual data is stored in a folder in the user data area
Win: c:\documents and settings\[user]\application data\adobe\ScriptStore
Mac: [user]\library\application support\adobe\ScriptStore
There are plenty of examples in Import from Camera on how to use it.
But the basics are (and most of this is in the top commented section of the library itself):
MyScript = {};
MyScript.store = ScriptStore.open( "$$$AStoragePalceForMyScript" );
ScriptStore.open - will launch ScriptStore, and open a "store" with the given name. The name can not contain spaces, and must be unique from all other store names. So use something goofy. If the store does not exist, it returns a new, empty store.
To put simple data into the store:
store.put( type, name, value );
Where type is a string - just a name - allows you to store more than one property of the same name, but delineating a "type" or category of data.
name is the name to store it under
value is the value
store.put( "metadata", "Fred", "Flinstone" );
This creates an xml structure like:
<metadata>
Doing it again:
store.put( "metadata", "Barney", "Rubble" );
yields:
<metadata>
Attempting to overwrite does exactly that.
store.put( "metadata", "Barney", "Fife" );
yields:
<metadata>
To get stored data:
store.get( "metadata", "Barney" );
returns "Fife"
You can also put Arrays into storage:
var ar = ["Fred","Barney","Wilma","Betty"]
store.putArray( "metadata", "FlintstoneAdults", ar );
and get arrays
store.getArray( "metadata", "FlintstoneAdults" );
In AdobeLibrary1, we created an object definition, Hashtable - which I find uniquely useful.
You can:
var ht = new Hashtable();
ht.put( "Fred", "Flintsone" );
ht.put( "Barny", "Rubble" );
ht.put( "Wilma", "Flintstone" );
ht.put( "Betty", "Rubble" );
store.putCollection( "metadata", "FlintFolk", ht );
and
var ht = store.getCollection( "metadata", "FlintFolk" );
And if these put and get methods aren't enough for you, you can create your own data structure and traverse it yourself.
store.root is the root XmlNode of the store.
So to make your own structure, use XmlNode.addNode( name, value );
myNode = store.root.addNode( "myNode" );
myDataNode = myNode.addNode( "Fred", "Flintstone" );
this creates an XML structure:
Once you have stored this sturcture with: store.save();
You find it this way:
var MyNode = store.root.findNode( "myNode" );
var Fred = myNode.findNode( "Fred" ).getValue();
You can find a node among multiple nodes:
store.findNode( name, count );
where count is an integer. Count = 0, it finds the first instance of a node with "name". Count = 1, it finds the second.
Or you can just get them all:
store.findNodes( name ); which returns a array of nodes
I hope you all find this as useful as I do.
Bob
Adobe Workflow Scripting
