Your prescription for increased productivity and profitability
For the last blog posts we have been builing a script to automate the creation of a slideshow using a multiple sselection object. First we created the slideshow, then the buttons. With this post we will create aa custom dialog to give the user two stylistic options for the slideshow:
Place buttons centered below the slideshow
Place buttons at either side of the slideshow
By design the user will be responding to the custom dialog before the document is created, For this reason we need to use the Application’s color swatch panel. The following creates a list of the swatch names including “None” and Registration” (which we don’t want).
tell application "Adobe InDesign CC 2018" set defaultList to name of swatches end tell colorList
As “None” and “Registration” are always items 1 and 2 of the list, the sccript can remove these simply by repeating a rest of list two times or by setting a new list to items 3 through the length of the list. The following uses the latter approach:
on getColorList () tell application "Adobe InDesign CC 2018" set defaultList to name of swatches set len to length of defaultList set colorList to items 3 thru len of defaultList return colorList end tell end getColorList
In looking at the Button Library panel we see that buttons 143 and 144 are left and right arrows colored blue. Similar pairs of buttons are 145 and 146: gray; 147 and 148: green; 149 and 150: red; 150 and 151: black.
One way to associate a color with a number is to use corresponding lists (or arrays). The buttonColor list is a name that identfiies the button pair by color. The colorNumber list is comprised of the number for the left-facing arrow. The right-facing arrow will be defined by adding 1 to the number for the left arrow chosen.
set buttonColor to {"Blue", "Gray", "Green", "Red", "Black"} set colorNumber to {143, 145, 147, 149, 151}
With the above information we can write the code to build the dialog. The dialog will be comprised of two enabling groups: one for each of the two styles offered. The code for a custom dialog gets a little intense because of its hierarchal nature: The dialog contains columns which contains rows, and rows contain objects.
Of course, rows can contain columns which can contain rows (and on…). The idea behind our code is to create a variable for any object that needs to be referenced later. Otherwise, each row or column is created using a tell (make row/column) statement. You can see how this goes together in the following:
--define values needed for the dialog set colorList to getColorList() set buttonColor to {"Blue", "Gray", "Green", "Red", "Black"} set btnNumbers to {143, 145, 147, 149, 151} set dlgName to "Slideshow Style" try --call the handler inside a try/on error to catch possibility of user canceling the dialo set dlgResult to doDialog(dlgName, true, colorList, buttonColor) on error errStr activate display alert ("Error: " & errStr) end try dlgResult (*Creates dialog with enabling groups; returns button color chosen for group chosen. Neither enabling group is defaulted*) on doDialog(dlgName, doCancel, colorList, buttonColor) tell application "Adobe InDesign CC 2018" set origLevel to user interaction level of script preferences set user interaction level of script preferences to interact with all set dlgRef to make dialog with properties {name:dlgName, can cancel:doCancel} tell dlgRef tell (make dialog column) tell (make dialog row) set eGroup1 to make enabling group with properties {static label:"Arrow buttons to sides", checked state:false} tell eGroup1 tell (make dialog column) tell (make dialog row) make static text with properties {static label:"Button Color Choice: ", static alignment:right align, min width:100} set colorDrop1 to make dropdown with properties {string list:colorList, selected index:0, min width:100} end tell end tell end tell end tell tell (make dialog row) set eGroup2 to make enabling group with properties {static label:"Library buttons to buttom of images", checked state:false} tell eGroup2 tell (make dialog column) tell (make dialog row) make static text with properties {static label:"Button Color Choice: ", static alignment:right align, min width:100} set colorDrop2 to make dropdown with properties {string list:buttonColor, selected index:0, min width:200} end tell --row end tell --column end tell --egroup end tell --row end tell --column end tell --dialog set userResponse to show dlgRef if userResponse is true then if checked state of eGroup1 is true then set styleRef to "style1" set itemSelected to (selected index of colorDrop1) + 1 else if checked state of eGroup2 is true then set styleRef to "style2" set itemSelected to (selected index of colorDrop2) + 1 end if end if --restore script preference destroy dlgRef set user interaction level of script preferences to origLevel if userResponse is false then error "User cancelled" end tell --application return {styleRef, itemSelected} end doDialog on getColorList() tell application "Adobe InDesign CC 2018" set defaultList to name of swatches set len to length of defaultList set colorList to items 3 thru len of defaultList end tell end getColorList
Notice that a value of 1 is added to the choice made in a dropdown. When inside the dialog, AappleScript begins its list count at 0; outside of the dialog it begins with 1. (Just a little to twist those brain cells a little.)
Depending on the enabling group chosen and the item chosen from its dropdown, the appropriate button needs to be accessed or created. Our final script will need a handler to get a reference to the left and right arrow buttons.
If the user selects the first enabling group, the result of the dialog will be {"style1", number from dropdown selection}.
Similarly, choosing the second enabling group will return {"style2", number from dropdown selection}.
Referring to the code from our previous blog post, we see that the addButton handler for the Library buttons requires the following values to be defined:
To calculate the place points we need the dimensions of the document. If you have been following along, you will knw that the dimensions are calculated based on the size of the images selected. For our purpose here, we will assume a web intent document having dimensions of 800 x 660 pixels has already been created and is active. (The 60 extra pixels are for the margin at the bottom of the page needed for the Library Button style.)
To test the handler for this segment, we will use arbitrary values to represent values returned from the dialog.
set buttonColor to {"Blue", "Gray", "Green", "Red", "Black"} set btnNumbers to {143, 145, 147, 149, 151} set dlgResult to {"Style1", 4} if item 1 of dlgResult is "Style1" then set btnNumber to item 2 of dlgResult set btnNum1 to item btnNumber of btnNumbers set btnNum2 to btnNum1 + 1 --position, page width, page height, button width, button height, margin set placeInfo to getPlaceInfo("bottom", 800, 660, 19, 18, 24) else if item 1 of dlgResult is "Style2" set btnWid to 15 set btnHgt to 40 set margin to 30 set clrIndex to item 2 of dlgResult set btnColor to item clrIndex of colorList set placeInfo to getPlaceInfo("Sides", 800, 600, btnWid, btnHgt, margin) end if (*Calculates information for placing buttons depending on style selected Assumes measurement unit is set to pixels. Setting measurement units is accomplishe when the document is created*) on getPlaceInfo(pos, pgWid, pgHgt, btnWid, btnHgt, margin) if pos is "Sides" then set path1 to {{370, 430}, {355, 450}, {370, 470}} set path2 to {{400, 430}, {415, 450}, {400, 470}} set gBounds1 to {430, 350, 470, 375} set gBounds2 to {430, 400, 470, 425} set x0 to margin set b2x0 to pgWid - (margin + btnWid) set cy to round (pgHgt / 2) set y0 to cy - (btnHgt / 2) set y1 to y0 + btnHgt set x1 to x0 + btnWid set gBounds1 to {y0, x0, y1, x1} set gBounds2 to {y0, b2x0, y1, b2x0 + btnWid} set path1 to {{x1, y0}, {x1 - btnWid, cy}, {x1, y1}} set path2 to {{b2x0, y0}, {b2x0 + btnWid, cy}, {b2x0, y1}} return {gBounds1, path1, gBounds2, path2} else if pos = "bottom" then set cx to round (pgWid / 2) set cy to (pgHgt - (margin + (btnHgt))) set placePt1 to {(cx - (margin + (btnWid / 2))), cy} set placePt2 to {(cx + margin), cy} return {placePt1, placePt2} end if end getPlaceInfo
At this point we have a dialog that allows the user to choose between two styles for the Slidesow we started in our blog post of January 16, In this blog we added code to calculate the placement information needed for either of the two styles. As there is already enough information here to make most heads spin, we will leave the final touches for the project for our next blog. Until then, we encourage you to experiment with the custom dialog. Maybe add more choices for the Arrow button (line style, stroke weight, etc.).
For the brave in heart, you may want to see if you can add the code to create/place the buttons from code developed in the previous blog (January 24). With this, you should be able to complete the project using code found in that post. The handler for the library button is used as is with the only change being the name of the handler and call it by adding the following to the Test Place Info handler.
set btn1 to doLibraryButton("LeftButton", item 1 of placeInfo, btnNum1) set btn2 to doLibraryButton("RightButton", item 2 of placeInfo, btnNum2)
You can use the handler for the Arrow But=ton (using the aaddButton handler (found under the heading Buttons With Stroke Only). You can use this handler as is using the following to call the handler:
set btn1 to addButton("LeftButton", item 1 of placeInfo, item 2 of placeInfo, false) set btn2 to addButton("RightButton", item 3 of placeInfo, item 4 of placeInfo, false)
However, the button will be colored “Paper”. It will take a little more effort to modify the haddler to aallow the color chosen in the custom dialog to be used.
Keep tuned as this project is completed in our next blog post. We will also be posting the entire script for download from our website at that time.
Code presented is intended for demonstration only. No repreentation is made as to its completeness or accuracy. Users are cautioned to use the code at their own discretion.<;p>