I am trying to fix all of the hyperlinks in my indesign files, and replace the https with http. right now, in order for it to work, I run this script..
var
i;
hls = app.activeDocument.hyperlinkURLDestinations;
for (i = 0; i < hls.length; i++) {
if (!hls[i].destinationURL.match('http://')) {
hls[i].destinationURL = 'http://' + hls[i].destinationURL;
}
}
followed by this script, choosing https to be replaced by http...
main();
function main(){
var d = app.dialogs.add({name:"Replace Hyperlink URL Values"});
var col1 = d.dialogColumns.add();
var col2 = d.dialogColumns.add();
col1.staticTexts.add({staticLabel:"Find (GREP):"});
col1.staticTexts.add({staticLabel:"Replace:"});
var find = col2.textEditboxes.add({minWidth:100});
var change = col2.textEditboxes.add({minWidth:100});
var result = d.show();
if(!result){
d.destroy();
return;
}
var grepForFind = RegExp(find.editContents,"g");
var grepForReplace = change.editContents;
d.destroy();
var dests = app.documents[0].hyperlinkURLDestinations.everyItem().getElements();
for(var i=0;i<dests.length;i++){
dests[i].destinationURL = dests[i].destinationURL.replace(grepForFind,grepForReplace);
}
}
Once both of these have been ran, I notice that the "http://" has been duplicated on the hyperlinks that already contain "http://".
So I run the second script again replacing (http:// + http://) with "http://" which solves the problem.
My question, is how to make it into a single script that would work the first time.
**Note:**The second script presents this error if the first is not run, which baffles me as well.
Any and all help would be appreciated.