Automating Adobe InDesign 2019 - AppleScript


user-input_dialogs-iV

Tuesday, February 12, 2019

To round out our discussion on InDesign custom dialogs, we will look at three widgets that have specialized behaviors: enabling groups, measurement editboxes, and comboboxes.

Measurement Editbox

The measurement editbox is similar to a real editbox in that it can accept a number with a decimal value. Additionally, measurement editboxes have a unit value property which becomes part of the value shown for its edit value. This can be set as points, picas, inches, pixels, millimeters, centimeters, and more. The thing that you need to keep in mind about measurement editboxes is that, irrespective of the unit value set, the value shown in the editbox is converted to points foor comparison to the minimum and maximum values allowed and is always returned as points. This takes a little getting used to. For instance, if you set the unit value to inches and you want the minimum value to be 1 imch, the minimum value for the measurement editbox needs to be set to 72. Try this out with the following example:

Measurement Editbox

--pass name and can cancel values to handler
set valueList to doDialog("Test", false)

on doDialog(dlgName, canCancel)
   tell application "Adobe InDesign CC 2019"
	activate
	set dlgRef to make dialog with properties {name:dlgName, can cancel:canCancel}
	set origLevel to user interaction level of script preferences
	set user interaction level of script preferences to interact with all
	tell dlgRef
	   tell (make dialog column)
		tell (make dialog row)
		   make static text with properties {static label:"width"}
		   set widField to make measurement editbox with properties {edit units:inches, min width:72, minimum value:72, maximum value:10 * 72, edit value:72}
		end tell
	   end tell --column
	end tell --dialog
	set userResponse to show dlgRef
	--default values
	set valueList to {}
	set borderWid to 0
	if userResponse is true then
	   set borderWid to edit value of widField
	   set valueList to {borderWid}
	end if --userResponse is true
	destroy dlgRef
	set user interaction level of script preferences to origLevel
	return valueList
   end tell
end doDialog

Notice that the default edit value is converted to the unit value for display in the editbox.

measurement editbox in custom dialog...Measurement Editbox

Enabling Groups

Similar to a checkbox control, enabling groups have a static label and a checked state. Additionally, all of the dialog widgets created within the enabling group depend on the checked state of the group. In the following example, the radio buttons created within the enabling group are grayed out when the dialog is created. Only when the enabling group's checkbox is checked is the user able to interact with the radio buttons.

Enabling Group

--pass name and can cancel values to handler
set valueList to doDialog("Test", false)

on doDialog(dlgName, canCancel)
   tell application "Adobe InDesign CC 2019"
       activate
       set dlgRef to make dialog with properties {name:dlgName, can cancel:canCancel}
       set origLevel to user interaction level of script preferences
       set user interaction level of script preferences to interact with all
	  tell dlgRef
	     tell (make dialog column)
		set enable1 to make enabling group with properties {static label:"Add border", checked state:false}
		tell enable1
		   tell (make dialog column)
		      tell (make dialog row)
			make static text with properties {static label:"Corner type: "}
			set radioGroup to make radiobutton group
			tell radioGroup
			   make radiobutton control with properties {static label:"Square corner", checked state:true}
			   make radiobutton control with properties {static label:"Round corner"}
			end tell
		      end tell --row
		   end tell
		end tell --enabling group
		--other widgets added here
	   end tell --column
	end tell --dialog
	set userResponse to show dlgRef
	--default values
	set valueList to {}
	set borderWid to 0
	if userResponse is true then
	   set addBorder to checked state of enable1
	   if addBorder then
	      set valueList to {selected button of radioGroup}
	   end if
	end if --userResponse is true
	destroy dlgRef
	set user interaction level of script preferences to origLevel
	return valueList
   end tell
end doDialog

Enabling Group in dialog...Enabling Group

Combobox

The various types of comboxes are similar to a dropdown but add a text entry field in addition to the dropdown. The types of comboboxes include an angle combobox, integer combobox, percent combobox and real combobox. These have properties that include an edit value and an edit contents property but not a selected index. See how a typical measurement combobox works in the following:

Measurement Combobox

--pass name, can cancel, and string list values to handler
set measString to {"1 in", "2 in", "10 in"}
set valueList to doDialog("Test", false, measString)

on doDialog(dlgName, canCancel, measString)
   tell application "Adobe InDesign CC 2019"
	activate
	set dlgRef to make dialog with properties {name:dlgName, can cancel:canCancel}
	set origLevel to user interaction level of script preferences
	set user interaction level of script preferences to interact with all
	tell dlgRef
	   tell (make dialog column)
	      tell (make dialog row)
		 make static text with properties {static label:"width"}
	         set widField to make measurement combobox with properties {string list:measString, edit units:inches, min width:72, minimum value:72, maximum value:10 * 72, edit value:72}
	      end tell
	   end tell --column
	end tell --dialog
	set userResponse to show dlgRef
	--default values
	set valueList to {}
	set borderWid to 0
	   if userResponse is true then
		set borderWid to edit value of widField
		set valueList to {borderWid}
	   end if --userResponse is true
	   destroy dlgRef
	set user interaction level of script preferences to origLevel
	return valueList
   end tell
end doDialog

Measurement combobox in custom dialog...Measurement Combobox

Notice that the behavior of the measurement combobox is similar to that of the measurement editbox with the exception that it provides a list of suggested values. In addition to the suggested values, the user is able to enter any value into the combobox as long as it is within the range set by the minimum and maximum values.

Edit vs Content Values

As with other widgets, comboboxes and measurement editboxes can return either a string value or a numerical value. If you want a string value returned, use edit contents instead of edit value to establish the default as well as the return value. Use either edit contents or edit value; don't mix the two.

Onward and Upward

Now that you have the basics, you should be able to create a user dialog that has all of the capability that you will need for the majority of your scripts. Test your dialog scripts thoroughly to make sure to check all possible values returned to be sure you have taken care of all possible user entries (and errors).

Disclaimer:
Scripts provided are for demonstration and educational purposes. No representation is made as to their accuracy or completeness. Readers are advised to use the code at their own risk.

Trackback Link
http://www.yourscriptdoctor.com/BlogRetrieve.aspx?BlogID=18424&PostID=1528525&A=Trackback
Trackbacks
Post has no trackbacks.