Hi,
here's a script that might help you. I made it and tested it only for InDesign CS5.5.
How to use it: select any object in InDesign then run the script. At first, the script will try to see in the clipboard has valid URL (well, a text startiong with http…) and if so, the clipboard will be take as a good URL for the new created button. If no valid URL in the clipboard, the script will ask for the URL to be entered manually. If the ibject is a text frame, the script will try to take the text from inside the frame as a URL – if not valid, then the dialog pops up.
// -------------------------------------------- BEGIN SCRIPT ----------------------------------------------
if (app.selection.length==1) {
//get the selected object (only one object)
var xOBJECT = app.selection[0];
var xPAGE = xOBJECT.parentPage;
var xBOUNDS = xOBJECT.geometricBounds;
//create the button
var xBUTT = xPAGE.buttons.add({geometricBounds:xBOUNDS});
//add selected object to the normal state
xBUTT.states.item(0).addItemsToState(xOBJECT);
//create the gotoURL behavior
var xGOTOURL = xBUTT.gotoURLBehaviors.add({behaviorEvent:BehaviorEvents.mouseUp});
//get the clipboard
var xTEMP = app.documents[0].textFrames.add(); xTEMP.insertionPoints[-1].select(); app.paste(); var xCLIP = xTEMP.parentStory.contents; xTEMP.remove();
//check the clipboard or text frame's text; if it does not starts with "http" then it's not good and a dialog asking a good URL will popup
if (xOBJECT.constructor.name!="Rectangle")
{
var xURL = xOBJECT.parentStory.contents;
} else {
var xURL = xCLIP;
};
if (xURL.substring(0, 6)!="http://") {
// do the dialog here
var xDIAG = app.dialogs.add();
with (xDIAG.dialogColumns.add().dialogRows.add()){staticTexts.add({staticL abel:"Enter URL:"}); var xURLTEXT = textEditboxes.add({editContents:xCLIP, minWidth:160});}
var xRESULT = xDIAG.show({name:"Button creation"});
if (xRESULT == true){xURL = xURLTEXT.editContents; xDIAG.destroy();} else { xURL="http://"; xDIAG.destroy();}
}
// set the URL to the behavior
xGOTOURL.url=xURL;
// -------------------------------------------- END SCRIPT ----------------------------------------------
Have fun!