Skip to main content
Participating Frequently
September 28, 2012
Answered

assign goto url to all buttons

  • September 28, 2012
  • 1 reply
  • 5298 views

Hi!

I have a document with multiple pages.

In the head of every page is a button (let say the name of it is in every case: 'buttonXY'). There are some more buttons at the pages, but with other names.

How can i change every buttonXY-button's action (the button already have the action) 'go to url' (on all pages) to a specified url (to defined in the script or as input form).

thanks a lot,

Christian

This topic has been closed for replies.
Correct answer Jongware

Jongware, thank you again!

yes ... now you help me a bit to identify methods and variables. :-)

but nevertheless at the moment i don't understand how i can systematicly reach a value or function.

in php for example i can print out a whole object or array (print_r()) and can systematicly fetch that what i need ...

now i have upped my (cleaned) .indd here.

there you can see, at every header is a button with the action gotourl and the value: "navto://lbt_einstieg_h" <- and I want to search and replace that to (for example) to "navto://XYZ_einstieg_h" on every page in the document.

There are more buttons in the upper right side for open and close a hover <- they should be untouched by the script.

could you please took a look about it?

thanks,

Christian


Something like this? This code inspects all buttons in the document and gathers the ones with a single gotoURLBehavior. It shows the list in a simple dialog, where you can also enter a new URL. Press OK to change the listed URLs, or Cancel to bail out.

If the dialog shows other URLs than the one(s) you want to change, you'll have to devise a way to discern these. (Although another way could be to add checkboxes for each one to change, but that's a bit more work )

allButtons = app.activeDocument.buttons;

urlButtons = [];

urls = [];

for (i=0; i<allButtons.length; i++)

{

  if (allButtons.gotoURLBehaviors.length == 1)

  {

    urlButtons.push (allButtons);

    urls.push (allButtons.gotoURLBehaviors[0].url);

  }

}

urlDialog = app.dialogs.add ({name:"URL buttons",canCancel:true});

with (urlDialog)

{

with (dialogColumns.add())

{

    for (i=0; i<urls.length; i++)

      staticTexts.add ({staticLabel:urls});

    edBox = textEditboxes.add({editContents:"http://www. ...", minWidth:240});

}

}

if (urlDialog.show())

{

  for (i=0; i<urlButtons.length; i++)

    urlButtons.gotoURLBehaviors[0].url = edBox.editContents;

}

1 reply

Participating Frequently
October 1, 2012

ok ... i thought about and checked the document. it was a bit of nonsense i wrote in my question.

every button gets another name while creating my document <- so the buttons names are unique.

but i could care about that every button i want to change (not every -> only they i want to change) have the same pre-filled content.

i have a great problem to get the content of a button ... tried a lot of "app.activeDocument.pages[1].buttons[1].gotoURLBehaviors.item[1]" and such ... but only got error-messages ... but in the case of search-and-replace all the buttons with the to specified pre-filled content i need a array of all button in the document and a foreach about all of them.

i don't expect the whole script for that ... but some ideas (especially about to fetch the buttons gotoURLBehavior) woul be realy great!

Thank you!

Jongware
Community Expert
Community Expert
October 1, 2012

mrdonthave wrote:

[..] i have a great problem to get the content of a button ... tried a lot of "app.activeDocument.pages[1].buttons[1].gotoURLBehaviors.item[1]" and such ... but only got error-messages ...

Can you try some more, but this time taking into account that Javascript starts counting at 0?

It's not easy to write a complete script without seeing your actual document, but it seems you know exactly what you want to do (just not how to do it ).

Participating Frequently
October 1, 2012

hi Jongware,

thank you for your answer.

also, if i try "alert(app.activeDocument.pages[0].buttons[0].gotoURLBehaviors.item[0]);" i've got a error: "Fehlernummer 45 / Fehlerzeichenfolge: Objekt ist ungültig (Error Number 45 / Object is not valid)".

what i want to do:

in my document i have a lot of buttons in a lot of pages (the document is generated auotmaticly) and i only want to change the content of this buttons with a to specified content (search/replace for the goto url behaviour field). all other buttons should be unchanged. (MAYBE thats important: the buttons are grouped with other elements)

thank you,

Christian