Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Newbie--AppleScript for InDesign CS5 help needed

New Here ,
Nov 10, 2010 Nov 10, 2010

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.

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 10, 2010 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2010 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2010 Nov 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.

Screen shot 2010-11-10 at 11.28.52 AM.png

So what should my correct syntax be?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 10, 2010 Nov 10, 2010

I think you will first need to…

set hpdest to make new hyperlink page destination with properties ¬

{Blah, Blah, Blah}

then pass that to your make hyperlink…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2010 Nov 10, 2010

Not quite there yet.

I did as you suggested but whatever I do it returns:

"error "Adobe InDesign CS5 got an error: Can’t make class hyperlink page destination." number -2710 from hyperlink page destination to class"

or

"error "Adobe InDesign CS5 got an error: Can’t make class hyperlink." number -2710 from hyperlink to class"

Is there something about InDesign CS5 that is different from CS4 with regards to what this class is supposed to be named? Again, I can find no documentation.

Your help is much appreciated.

This is a tiny script that is needed for a big, time-consuming job, and I would be willing to pay somebody to write the script for me offline if you can guarantee you'll keep at it until it works.

This is my first time writing an AppleScript!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2010 Nov 10, 2010

Maybe I should get somebody good at JavaScript if that's better documented?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 10, 2010 Nov 10, 2010

Hi WheatWilliams,

It's partly a problem of your tell context. In your example, telling the InDesign application to make a hyperlink. That won't work--you need to tell the document to make the hyperlink (as in Muppet Mark's example--thanks for pitching in, Muppet Mark!).

Here's a really basic example:

tell application "Adobe InDesign CS5"

set myDocument to make document

tell myDocument

set horizontal measurement units of view preferences to points

set vertical measurement units of view preferences to points

set myTextFrame to make text frame with properties {geometric bounds:{72, 72, 144, 288}, contents:"Hyperlink destination"}

set myText to object reference of text 1 of parent story of myTextFrame

set myHyperlinkTextDestination to make hyperlink text destination with properties {destination text:myText}

set myTextFrame to make text frame with properties {geometric bounds:{288, 72, 432, 288}, contents:"Hyperlink source"}

set myText to object reference of text 1 of parent story of myTextFrame

set myHyperlinkTextSource to make hyperlink text source with properties {source text:myText}

set myHyperlink to make hyperlink with properties {source:myHyperlinkTextSource, destination:myHyperlinkTextDestination}

end tell

end tell

Thanks,

Ole

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2010 Nov 10, 2010

Thanks guys. It's clear that I am in over my head here.

I mean no disrespect, but I do not need to learn how to write AppleScript.

I need to pay somebody to write one simple AppleScript for me so I can finish a huge project on a deadline.

And I don't understand your reference to making a new document in InDesign. I already have a 500-page document full of text, and full of tables of numbers that I need to attach hyperlinks to. There are many tables and many pages all formatted somewhat differently, with several different kinds of columns of numbers. What I want is a "macro" where I can select something with my mouse, invoke the script, and have the proper information filled in for that one number only.

Can someone step in and let me hire him or her to solve this problem?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 10, 2010 Nov 10, 2010

Hi WheatWilliams,

Something like this, then:

tell application "Adobe InDesign CS5"

set myTextObjects to {text, character, word, text style range, line, paragraph, text column, cell, table, row, column}

if (count documents) is greater than 0 then

set mySelection to selection

if (count mySelection) is equal to 1 then

tell document 1

--Is the selection a text selection?

if class of item 1 of mySelection is in myTextObjects then

set myText to item 1 of mySelection

try

set myErrorString to "Selection already contains a hyperlink text source."

--Create the hyperlink text source.

set myHyperlinkTextSource to make hyperlink text source with properties {source text:myText}

set myPageNumber to item 1 of mySelection as integer

set myPageNumber to myPageNumber + 44

set myErrorString to "Could not get page number."

set myPage to page myPageNumber

set myErrorString to "Could not create hyperlink page destination."

--Create they hyperlink page destination.

set myHyperlinkPageDestination to make hyperlink page destination with properties {destination page:myPage}

set view percentage of myHyperlinkPageDestination to 100

--Now use the source and the destination to create the hyperlink.

set myErrorString to "Could not create hyperlink."

set myHyperlink to make hyperlink with properties {source:myHyperlinkTextSource, destination:myHyperlinkPageDestination}

set myErrorString to "Cound not format hyperlink."

--Apply formatting to the hyperlink (could be done in the properties record, above).

set visible of myHyperlink to true

set border color of myHyperlink to blue

set border style of myHyperlink to solid

on error

display dialog myErrorString

end try

end if

end tell

end if

end if

end tell

Thanks,
Ole

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 10, 2010 Nov 10, 2010
LATEST

thank you very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines