Skip to main content
Participating Frequently
November 10, 2010
Question

Newbie--AppleScript for InDesign CS5 help needed

  • November 10, 2010
  • 2 replies
  • 2583 views

How can I select a page number in a table (a text string as a Source) and have an AppleScript read that text string and convert it to an integer value?

I have to put over 1,200 hyperlinks into a document that already has page numbers in tables. Each page number (Source) will be assigned a hyperlink to go to that page (Destination).

The page numbers in tables are in the preface to my document, which is 44 pages in length.

The actual pages in the main body of my document are numbered 1-432. Thus, the 45th page in the document is Page 1 to the person reading it, and the 476th page is Page 432.

So if a table in my preface has a page number of 32, for instance, the actual page number I want as a Destination is 32 + 44, or page 76.

If I manually double-click to select the text of a number "x" in a table as a Source, I want to write a script that when invoked will

read the text string I have selected

convert it to an integer value equal to the number in the text string

add 44 to that value

create a hyperlink that goes to the destination page number that corresponds to that value

Thanks.

This topic has been closed for replies.

2 replies

Participating Frequently
November 10, 2010

thank you very much.

Muppet_Mark-QAl63s
Inspiring
November 10, 2010

I don't have CS5 but you could give this a try just to get you going…

tell application "Adobe InDesign CS2"

tell the active document

set selected to selection

if (count of selected) = 0 then

display dialog "No Selection?" giving up after 2

else

try

set destPage to (every text of selection) as integer

set destPage to destPage + 44

display dialog "Destination Page: " & destPage giving up after 2

on error

display dialog "Selected text was NOT coerced to number?" giving up after 2

end try

end if

end tell

end tell

Participating Frequently
November 10, 2010

I can't get AppleScript and InDesign CS5 to recognize

make new hyperlink

or

make hyperlink

So what should the command and class be called? I can't find any documentation.

Participating Frequently
November 10, 2010

Here's my attempt:

tell application "Adobe InDesign CS5"

set mySelection to selection

set myNumber to (mySelection as integer)

set myNumber to myNumber + 44

make new hyperlink with properties {page:myNumber, zoom setting:fixed, visible:true, width:thin, border color:blue, style:solid}

end tell

But this isn't working. The error message is "Can't make class hyperlink".

I don't want a new hyperlink with a URL; I want a hyperlink with page number.

If you manually open the New Hyperlink dialog box, the first field needs to say Link To:Page, "Page" being selected from the pull-down menu.

So what should my correct syntax be?