InDesign CS5 question on how Variables are accessed

Hi, It’s been a while, since I worked in applescript. I have a working script that works with a slug that we put at the bottom of our documents. It checks for the proof number and add one if the option is chosen, and it updates the date in a specified cell. I’m looking to better that script and put a dialog that would ask the date, like 0 would be today, 1 would be tomorrow, etc,… and a check mark that would update the proof number or not depending of what the user has choosen.

Here’s my script that works on the current spread. But only puts the current date, with no options to modify it.

– Begining of script 1
(* This is a work in progress to get the date to what ever I want –
set theNumber to 3
set theDay to (day of (current date)) as number
set TheDayValue to theDay + theNumber*)

set theDay to make_two_digit(day of (current date))
set theMonth to make_two_digit(month of (current date) as number)
set theYear to year of (current date)
set theDate to theYear & “-” & theMonth & “-” & theDay as string
global theDate

myDisplayDialog()
on myDisplayDialog()
tell application “Adobe InDesign CS5”
set myDialog to make dialog with properties {name:“Update Slug”}
tell myDialog
tell (make dialog column)
tell (make dialog row)
tell (make dialog column)
make static text with properties {static label:“Options:”}
end tell
tell (make dialog column)
set myButtons to make radiobutton group
tell myButtons
make radiobutton control with properties {static label:“Active Spread: Update date and number”, checked state:true}
make radiobutton control with properties {static label:“Active Spread: Update date only”}
end tell
end tell
end tell
end tell
end tell
set myResult to show myDialog
if myResult is true then
set myOption to (selected button of myButtons) + 1
destroy myDialog
if myOption is 1 then
my UpdateSlugCompleteSpread()
else if myOption is 2 then
my UpdateSlugDateSpread()
end if
else
destroy myDialog
end if
end tell
end myDisplayDialog

on UpdateSlugCompleteSpread()
–Changes the Slug Number and date on the active spread
tell application “Adobe InDesign CS5”
–this line is to make it work on the active layer only
tell active document
set myLayer to active layer of layout window 1
set myPage to active spread of layout window 1
try
set Slugframe_list to (page items whose name is “SlugFrame”) of myPage
repeat with j from 1 to count of Slugframe_list
set Slugframe to item j of Slugframe_list
try
set mynumber to (((text of cell id 11 of table 1 of Slugframe) as string) as number)
set mynumberText to (mynumber + 1) as string

–remove the if statement if you need it to be on all layers
if Slugframe’s item layer = myLayer then
set text of cell id 11 of table 1 of Slugframe to mynumberText
set text of cell id 16 of table 1 of Slugframe to theDate
end if
end try
end repeat
end try
end tell
end tell
beep
end UpdateSlugCompleteSpread

on UpdateSlugDateSpread()
–Changes the Slug date only on the active spread
tell application “Adobe InDesign CS5”
–this line is to make it work on the active layer only
tell active document
set myLayer to active layer of layout window 1
set myPage to active spread of layout window 1
– try
set Slugframe_list to (page items whose name is “SlugFrame”) of myPage
repeat with j from 1 to count of Slugframe_list
set Slugframe to item j of Slugframe_list
– try
–remove the if statement if you need it to be on all layers
if Slugframe’s item layer = myLayer then
set text of cell id 16 of table 1 of Slugframe to theDate
end if
–end try
end repeat
–end try
end tell
end tell
beep
end UpdateSlugDateSpread

on make_two_digit(the_number)
if the_number is less than 10 then
set the_result to “0” & the_number as string
else
set the_result to the_number as string
end if
end make_two_digit

–end of script 1


This is my attempt at modifying the script so far, but I’m stuck. My varialble TheDayvalue gives me an error because it’s not define yet, it is but only further in the script and I forgot how to go around that. I know, basic stuff, like I said, it’s been a while.

here’s the second script, which doesn’t work at all…

–begining of script 2
set theDay to make_two_digit(day of (current date)) as number

set theMonth to make_two_digit(month of (current date) as number)
set theYear to year of (current date)
set theDate to theYear & “-” & theMonth & “-” & theDayValue as string
global theDateValue

myDisplayDialog()
on myDisplayDialog()
tell application “Adobe InDesign CS5”
set myDialog to make dialog with properties {name:“Update Slug”}
tell myDialog
tell (make dialog column)
tell (make dialog row)

tell (make dialog column)
make static text with properties {static label:“Date: 0=Today 1=Tomorrow, etc,…”}
end tell
tell (make dialog column)
set mydate to make text editbox with properties {edit contents:“0”}
end tell

tell (make dialog column)

set myButtons to make radiobutton group
tell myButtons

make radiobutton control with properties {static label:“Active Spread: Update date and number”, checked state:true}

make radiobutton control with properties {static label:“Active Spread: Update date only”}
end tell
end tell
end tell
end tell
end tell
set myResult to show myDialog
if myResult is true then
–Get the values from the various editboxes.

set myString to (((edit contents of mydate) as string) as number)
set theDayValue to theDay + myString
set myOption to (selected button of myButtons) + 1
destroy myDialog
if myOption is 1 then
my UpdateSlugCompleteSpread()
else if myOption is 2 then
my UpdateSlugDateSpread()

end if
else
destroy myDialog
end if
end tell
end myDisplayDialog

on UpdateSlugCompleteSpread()
–Changes the Slug Number and date on the active spread
tell application “Adobe InDesign CS5”
–this line is to make it work on the active layer only
tell active document
set myLayer to active layer of layout window 1
set myPage to active spread of layout window 1
try
set Slugframe_list to (page items whose name is “SlugFrame”) of myPage
repeat with j from 1 to count of Slugframe_list
set Slugframe to item j of Slugframe_list
try
set mynumber to (((text of cell id 11 of table 1 of Slugframe) as string) as number)
set mynumberText to (mynumber + 1) as string

–remove the if statement if you need it to be on all layers
if Slugframe’s item layer = myLayer then
set text of cell id 11 of table 1 of Slugframe to mynumberText
set text of cell id 16 of table 1 of Slugframe to theDate
end if
end try
end repeat
end try
end tell
end tell
beep
end UpdateSlugCompleteSpread

on UpdateSlugDateSpread()
–Changes the Slug date only on the active spread
tell application “Adobe InDesign CS5”
–this line is to make it work on the active layer only
tell active document
set myLayer to active layer of layout window 1
set myPage to active spread of layout window 1
– try
set Slugframe_list to (page items whose name is “SlugFrame”) of myPage
repeat with j from 1 to count of Slugframe_list
set Slugframe to item j of Slugframe_list
– try
–remove the if statement if you need it to be on all layers
if Slugframe’s item layer = myLayer then
set text of cell id 16 of table 1 of Slugframe to theDate
end if
–end try
end repeat
–end try
end tell
end tell
beep
end UpdateSlugDateSpread

on make_two_digit(the_number)
if the_number is less than 10 then
set the_result to “0” & the_number as string
else
set the_result to the_number as string
end if
end make_two_digit

–end of script 2

I know, I’m still using radiobutton in the second script because I don’t know how to do the checkbox thing yet. I didn’t find any example of how to do those so you if you have one, and would like to share it, it’d appriciated it:-)

So, any help in solving this would be greatly appriciated, Thanks!

Jeff

Hi, Jeff. Instead of crafting so many handlers for updating dates, you can use InDesign’s Text Variable function, which is basically a symbol”à la automatic page numbering”that you can place anywhere and in the format of your choosing. Your date can include leading zeros, abbreviations, custom text, etc. http://help.adobe.com/en_US/InDesign/6.0/WS6A9BE096-77B2-4721-9736-797C4912B6C9a.html#WS3E9F3AD0-95D7-414a-BD4B-463A15119508a

Hi Marc,

I’m aware of that fonctionnality, but we have to be able to change it on the fly, and ideally for a future date. Like if we have to print the file today but the due date is in two days, we want the date for the day after tomorrow. Plus, my college told me that there was a bug in CS4 and CS5 which prevents such variables in ID to be copied, it crashes ID everytime you try to copy it. Not a pleasant surprise.

Thanks
Jeff

A symbol necessarily needs to be converted to text so it becomes static, otherwise, there is nothing usable to copy.

Regarding your supplied code, you can’t really concatenate something with an undefined variable, so that part can be pieced together with theDate at a later point. The myDisplayDialog handler is only called once and is the crux of your script, it is rightly in the code body and not a subroutine. You could make your code shorter if you’d roll all the handlers”with the exception of make_two_digit”into the body and just use ifs to meet the conditions, as everything except the initial parameters is directed to InDesign. theDateValue global is also orphaned; it looks like it was meant to be theDate.

Thanks Marc,

Following your advise, I’ve modified my script so that almost everything is inside the handler for the dialogbox. It’s probably not pretty, but for now, it works! So Thanks again. I really appreciate it:-)

Jeff