Skip to content

Commit 040a0e3

Browse files
committed
Cleanup scripting-xmp
1 parent 351542f commit 040a0e3

2 files changed

Lines changed: 1153 additions & 482 deletions

File tree

‎docs/scripting-xmp/accessing-the-xmp-scripting-api.md‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ if ( ExternalObject.AdobeXMPScript == undefined ) {
1111

1212
After the library has been loaded, these primary XMP classes are available in the global JavaScript namespace:
1313

14-
| [XMPMeta object](xmpscript-object-reference.md#xmpmeta-object) | Provides the core services of the XMP Toolkit. Allows you to create and delete<br/>metadata properties, and to retrieve and modify property values. |
15-
|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
16-
| [XMPFile object](xmpscript-object-reference.md#xmpfile-object) | Provides convenient I/O access to the main, or document level, XMP for a file. Allows<br/>you to retrieve existing metadata from a file, update file metadata, and add new<br/>metadata to a file. |
14+
| Object | Description |
15+
| -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
16+
| [XMPMeta object](xmpscript-object-reference.md#xmpmeta-object) | Provides the core services of the XMP Toolkit. Allows you to create and delete<br/>metadata properties, and to retrieve and modify property values. |
17+
| [XMPFile object](xmpscript-object-reference.md#xmpfile-object) | Provides convenient I/O access to the main, or document level, XMP for a file. Allows<br/>you to retrieve existing metadata from a file, update file metadata, and add new<br/>metadata to a file. |
1718

1819
Additional top-level objects include array-handling utilities, a date-time object, and constant definitions that include namespace constants. The top-level objects provide access to additional support classes that encapsulate individual metadata properties, file information, and XMP packet information, and a utility that allows iteration through properties.
1920

@@ -37,22 +38,25 @@ In Adobe Bridge, you can pass XMP metadata between the built-in `Metadata` objec
3738
```javascript
3839
var thumb = new Thumbnail( new File( "/C/myImage.jpg") );
3940
app.synchronousMode = true;
40-
xmp = new XMPMeta( thumb.metadata.serialize() );
41+
42+
var xmp = new XMPMeta( thumb.metadata.serialize() );
4143
```
4244

4345
or:
4446
```javascript
45-
xmp = new XMPMeta( thumb.synchronousMetadata.serialize() );
47+
var xmp = new XMPMeta( thumb.synchronousMetadata.serialize() );
4648
```
49+
4750
- You can modify the metadata in an Adobe Bridge thumbnail by creating a new `Metadata` object with serialized XMP. Continuing the previous example:
4851
```javascript
4952
// Create a compact XMP packet
50-
newPacket = xmp.serialize( XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT ) );
53+
var newPacket = xmp.serialize( XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT ) );
5154
thumb.metadata = new Metadata( newPacket );
5255
```
56+
5357
- To write metadata back to the file for a thumbnail, you can access the thumbnail's file and create an [XMPFile object](xmpscript-object-reference.md#xmpfile-object) object to access the embedded metadata directly:
5458
```javascript
55-
xmp = new XMPFile( thumb.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
59+
var xmp = new XMPFile( thumb.spec.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE );
5660
```
5761
5862
!!! note
@@ -65,12 +69,12 @@ In Adobe Bridge, you can pass XMP metadata between the built-in `Metadata` objec
6569
This code creates an empty [XMPMeta object](xmpscript-object-reference.md#xmpmeta-object), uses it to set a metadata property, and serializes it to a string, which you could pass to an authoring tool, for example, or store in a file.
6670
6771
```javascript
68-
xmp = new XMPMeta();
72+
var xmp = new XMPMeta();
6973
xmp.setProperty( XMPConst.NS_XMP, "CreatorTool", "My Script" );
70-
xmpStr = xmp.serialize(); // Serialize the XMP packet to XML
74+
var xmpStr = xmp.serialize(); // Serialize the XMP packet to XML
7175
7276
// Retrieve property
73-
prop = xmp.getProperty(XMPConst.NS_XMP, "CreatorTool");
77+
var prop = xmp.getProperty(XMPConst.NS_XMP, "CreatorTool");
7478
$.writeln( "namespace: " + prop.namespace + "\n" +
7579
"property path + name: " + prop.path + "\n" +
7680
"value: " + prop ); // same as prop.value
@@ -83,14 +87,15 @@ $.writeln( "namespace: " + prop.namespace + "\n" +
8387
This code accesses an existing XMP packet, assuming the location has been assigned to a string variable. It sets the modification-date property to the current date and time, and stores the updated XMP packet back to the string, making it as small as possible.
8488
8589
```javascript
86-
xmp = new XMPMeta( xmpStr ); // Object initialized with xmp packet as string
87-
dateTime = new XMPDateTime( new Date() ); // Now
88-
oldModificationDate = mp.getProperty( XMPConst.NS_XMP, "ModifyDate", "xmpdate" );
90+
var xmp = new XMPMeta( xmpStr ); // Object initialized with xmp packet as string
91+
var dateTime = new XMPDateTime( new Date() ); // Now
92+
var oldModificationDate = mp.getProperty( XMPConst.NS_XMP, "ModifyDate", "xmpdate" );
93+
8994
$.writeln( "Old modification date: " + oldModificationDate );
9095
xmp.setProperty( XMPConst.NS_XMP, "ModifyDate", dateTime, "xmpdate" );
9196
9297
// Serialize to XML, in compact style
93-
xmpStr = xmp.serialize( XMPConst.SERIALIZE_USE_COMPACT_FORMAT );
98+
var xmpStr = xmp.serialize( XMPConst.SERIALIZE_USE_COMPACT_FORMAT );
9499
```
95100
96101
---
@@ -108,10 +113,12 @@ $.writeln( "XMPFiles batch processing example" );
108113
109114
// Define folder containing images (make sure that you use copies)
110115
var picFolder = "/c/temp/photos";
116+
111117
// Load the XMPScript library
112118
if ( ExternalObject.AdobeXMPScript == undefined ) {
113119
ExternalObject.AdobeXMPScript = new ExternalObject( "lib:AdobeXMPScript" );
114120
}
121+
115122
// Iterate through the photos in the folder
116123
var pics = Folder(picFolder).getFiles();
117124
for ( var i = 0; i < pics.length; i++ ) {
@@ -167,23 +174,24 @@ var xmpCommand = new MenuElement( "command", "Show XMP Properties", "at the end
167174
xmpCommand.onSelect = function(m) {
168175
169176
// Get the first selected thumbnail
170-
thumb = app.document.selections[0];
177+
var thumb = app.document.selections[0];
171178
172179
// If there is one, and it has metadata
173180
if ( thumb && thumb.metadata ) {
174181
175182
// Retrieve metadata from the thumbnail into an XMPMeta object`
176183
// ( if app.synchronousMode is set, use thumb.metadata )
177184
178-
xmp = new XMPMeta( thumb.synchronousMetadata.serialize() );
185+
var xmp = new XMPMeta( thumb.synchronousMetadata.serialize() );
179186
180187
// Retrieve some of the XMP property values
181188
// A simple property with a localized string value
182189
var msg = "Title: " + xmp.getLocalizedText( XMPConst.NS_DC, "title", null, "en" ) + "\n";
183190
184191
// An array property
185192
msg += "Authors of the document:\n";
186-
num = xmp.countArrayItems( XMPConst.NS_DC, "creator" );
193+
var num = xmp.countArrayItems( XMPConst.NS_DC, "creator" );
194+
187195
for ( var i = 1; i <= num; i++ ) {}
188196
msg += "* " + xmp.getArrayItem( XMPConst.NS_DC, "creator", i ) + "\n";
189197
}

0 commit comments

Comments
 (0)