Why Metadata

Metadata is a set of standardized information about a file. It describes the file’s content, origin, and other attributes and is most often stored inside the file itself. Metadata information can be manually added to a document in InDesign, Photoshop, or Illustrator by choosing File > File Info. InDesign’s dialog provides fields for entering the document’s title, author, copyright status, and a wealth of other information. All this is stored using Adobe’s Extensible Metadata Platform (XMP).

Metadata’s scriptable properties are found in the metadata preferences object for the document. If you look for metadata preference in InDesign’s AppleScript Dictionary you will find a list of all the properties exposed. Several of the items are read only (r/o). These are automatically entered and maintained by InDesign.

Having your user enter all of the information for a document’s metadata in a custom dialog may be more of a chore than is necessary.

For instance, you could simply supply a checkbox to indicate that copyright information should be added. If the user checks this box, the script would then add standard copyright information. If you have several options for the copyright information, you could provide a dropdown from which the user could choose.

Additionally, instead of having the user enter a name for author, this can be provided by the user name property for the application:

     tell application "Adobe InDesign CC 2014"
          set userName to user name
     end tell

This leaves document title, job name, description, and keywords as the values left for the user to provide. See if you can update the custom dialog from our previous blog so the user interface looks like the following. Make sure the routine (handler) returns the edit contents of the name and description fields, the checked state of the checkboxes, and the index for the template chosen.

With this information your script can create the document from the template. The script can then add the metadata using a routine similar to the following:

     (*Adds metadata from user input to document; performs second save*)
     on addMetadata(docRef, baseName, desc, kwords, doCopyright)
	   set keyList to textToList(kwords)
	   tell application "Adobe InDesign CC 2014"
		set userName to user name
		tell metadata preferences of docRef
			if doCopyright then
				set c to current date
				set theYear to year of c
				set copyright status to yes
				set copyright notice to "Copyrighted " & theYear & " your info here"
				set copyright info URL to metaURL
				set copyright status to no
			end if
			set author to userName
			set document title to baseName
			set description to desc
			set keywords to keyList
		end tell
		save docRef
	   end tell
     end addMetadata

Keywords are entered in the custom dialog using commas between each item. To convert this to a list as required for the metadata, we took advantage of AppleScript’s text item delimiters.

      (*returns list from comma delimited text*)
     on textToList(kwords)
	  set keyList to {}
	  if kwords is not "" then
		set oldDelims to AppleScript's text item delimiters
		set AppleScript's text item delimiters to ","
		set keyList to text items of kwords
		set AppleScript's text item delimiters to oldDelims
	  end if
	  return keyList
     end textToList

There are a number of ways to get a date stamp from AppleScript’s current date method. Our script uses the following:

     (*Returns date stamp as MMDDYY*)
     on getDateStamp()
	  set d to (current date)
	  copy d to b
	  set month of b to January
	  set theMonth to (text -2 thru -1 of ("0" & (1 + ((d - b + 1314864) div 2629728)) as string))
	  set theDay to (text -2 thru -1 of ("0" & day of d as string))
	  set theYear to (year of d as string)
	  return theMonth & theDay & text -2 thru -1 of theYear
     end getDateStamp

We will be posting the complete script to our AppleScript page so you can refer to it as a guide to creating your own script. It never ceases to amaze how fast a script like this can take care of a number of repetitive chores. Once you test out your script, be sure to add it to the Scripts panel for InDesign and give it a keyboard shortcut. Your hard work will start returning dividends each time you use a template to start a document.