Skip to main content
Known Participant
November 21, 2011
Question

Updating date and proof number in slug

  • November 21, 2011
  • 1 reply
  • 774 views

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

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

This topic has been closed for replies.

1 reply

John Hawkinson
Inspiring
November 24, 2011

Jeff: Your script is too long to reasonably expect people to read and understand. You'll really need to pare your question down into smaller and more manageable chunks. This is probably a good exercise for your learning, anyhow.

With respect to:

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.

Well, yes. You cannot use a variable before you define it, scripts execute in order, so this sequence makes no sense:

set theDate to theYear & "-" & theMonth & "-" & theDayValue as string

...

set theDayValue to theDay + myString

The clear answer is to defer setting theDate until after such time as you set theDayValue. That is, move it down in the script. That may necessitate other changes, of course.

Bite-sized chunks, please. Thanks.

Happy turkeys.