Skip to main content
Known Participant
June 30, 2005
Question

So What the heck is AdobeLibrary2.jsx?

  • June 30, 2005
  • 3 replies
  • 811 views
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
This topic has been closed for replies.

3 replies

Participating Frequently
November 30, 2008
Thanks

Good Luck.
______
My Si tes
Known Participant
July 16, 2005
Feel free.

I'll warn you that I just ran into a bug in the XML parser, though. I was working on a recursive arbitrary object serializer/deserializer. I am working on a fix, should have it this week.

I also extended XmlNode to handle namespaces. I'll post that code when it's ready.

Bob
Known Participant
July 16, 2005
I've got some code that I would like to have run portably between CS and CS2.
I'd like to use your XML stuff in AdobeLibrary2.jsx because:
1) I don't have to write it
2) It comes bundled with CS2
3) It's "free", sorta.

My problem is that it does not come bundled with CS which mean I would have to
include AdobeLibrary2.jsx with my script or strip out the XML stuff and include
it in my package.

I don't have a problem with the mechanics of this process. What is not clear,
howver, is what the legal ramifications are of giving AdobeLibrary2.jsx to
someone who has not yet purchased a copy of a CS2 product. I'm not a lawyer so
asking me to read the licensing agreements is an effort in futility. It's real
easy for a layman like myself to misinterpret legalese.

What I would like is clarification from someone at Adobe as to what the
re-distribution policy is for AdobeLibrary2.jsx. I can go download a number of
different Free XML JS implementations, but I'd rather use your stuff.

thanks for the help.

ciao,
-X
Participating Frequently
July 16, 2005
I asked Bob this same question and here is the answer that he gave me:

As for using the functions, they are there as a library for everyone's
use. No need to give credit. Note that the libraries are only loaded
into bridge - you can't use them in any of the point apps unless you
copy/paste them into your point app scripts. You can also feel free to
use any of the Adobe provided scripts or parts of them in your own work.
We provide scripts as samples. We try to make them as "real world"
useful as we can, but we really consider them a starting point for all
scripters to use to their benefit.
Bob Stucky

Larry