Add Asset to Chosen Library

In this blog we will continue to build some handlers for an AppleScript that will provide a number of options for working with InDesign libraries.

To complete our script we will be adding the following:

  • A check to see if the user has a selection in an InDesign document
  • If there is a selection the custom dialog will add a third enabling group for entering a name, description, and asset type
  • If the user enters a name for an asset type, the library reference chosen will store the asset

Updating Logic

As with many scripts, once you start working with it you may discover your initial approach to the problem could be simplified or made better in some way. So it is with our library script. To simplify, it was decided to have just one list of libraries from which the user can choose. If the library is not open, the script can open it. So much simpler. The only downside to this approach is that the list of libraries from which the user will have to choose could be quite long.

Custom Dialog with Enabling Group for adding selected page item to chosen library

Once a library is selected in the custom dialog, a reference to the library is established in a handler named getLibraryReference:

(*Returns reference to library; opens library if not open *)
on getLibraryReference(libName, libPath)
	tell application "Adobe InDesign CC 2014"
		if not (exists library libName) then
			set fileAlias to (libPath & libName) as alias
			set libReference to open fileAlias
			set libReference to library libName
		end if
	makes library referenced the active panel
                --makes library referenced the active panel
                set libPanel to associated panel of libReference
		if visible of libPanel is false then
			set visible of libPanel to true
		end if
	end tell
	return libReference
end getLibraryReference 

Notice the code that makes the library referenced the active panel.

Check forSelection

The custom dialog will only add an enabling group for entering asset information if there is a selection. To check for a selection, the following handler is added to the script:

(*checks for selection in document. If no selection an empty list is returned.*)
on checkSelection()
	set selItem to {}
	tell application "Adobe InDesign CC 2014"
			if selection is not {} then
				set selItem to item 1 of selection
			end if
		end try
	end tell
	return selItem
end checkSelection

Add Enabling Group

If there is a selection, an enabling group is added to the dialog with fields for the user to enter a name and description. Also a dropdown from which to select the asset type.

if selectionRef is not {} then
	make dialog row
		set enable3 to make enabling group with properties {static label:"Add Selection to Library", checkedState:false}
	tell enable3
		tell (make dialog column)
			tell (make dialog row)
				make static text with properties {static label:"Asset Name: "}
				set assetField to make text editbox with properties {min width:300}
			end tell
			tell (make dialog row)
				make static text with properties {static label:"Description:  "}
				set assetDescField to make text editbox with properties {min width:300}
			end tell
			set assetType to make dropdown with properties {string list:assetTypes, selected index:0, min width:316}
		end tell
	end tell
end if

The entire script will be added to our AppleScript page, Monday October 6. It will be our featured script for the month of October.

Onward and Upward

All that is left is the need for a script to open a chosen asset to the page. We will leave this for our next blog (Monday October 6). Meanwhile, check this blog or watch for our Twitter feeds ( for exciting news coming soon.