Copy link to clipboard
Copied
Hi there,
I've been using this other forum post as a guide : Shared Hyperlink Destination (thread/791822) but unfortunately I can't quite get the behaviour i need.
Essentially I have documents that contain lots of shared destination URL hyperlinks. So there are multiple shared destinations and there are multiple hyperlinks using each shared destination.
I need to give each hyperlink their own destination URL and remove all shared urls. This then allows me to loop through all the hyperlinks and individually adjust their destination URL based on some other criteria (which I do later in the script).
My understanding is that to remove shared destinations I need to change the "hidden" property from "false" to "true" for shared destinations. It also seems that the only way to do this is to delete and recreate the hyperlink URL destination.
The problem with my current approach is that it removes the shared destination correctly, but it only adds an unshared location back to one of the hyperlinks that was using that shared destination. All the other hyperlinks that were using that shared destination now have NO destination value.
This has been my approach :
The above works perfectly for the current hyperlink, but all other hyperlinks that used that shared Destination URL now have no value.
To solve the problem I'm thinking the following approach might work but I'm having trouble working out the correct code:
My key problem is I don't know what javascript I need to write to for Step 3 - how do I get that list of hyperlinks that use the current hyperlinkURLDestination??? Any help to work out how to do that (or any suggestions on a better approach) would be greatly appreciated!
Many thanks, HJ
Thanks Pickory - I'll probably use this code for another issue. As for this issue I ended up going with this solution:
1. Loop thru all hyperlinks and put a copy of the URLdestination text into the hyperlink label
2. Once all hyperlinks have been looped thru, delete all shared hyperlink URLdestinations
3. Now loop back thru hyperlinks again and take the value in the label and use it to re create the hyperlink URLdestination for that hyperlink.
Its probably not the fastest option in terms of performa
...Copy link to clipboard
Copied
Here is another idea that I might try:
1. Loop thru all hyperlinks and put a copy of the URLdestination text into the hyperlink label
2. Once all hyperlinks have been looped thru, delete all shared hyperlink URLdestinations
3. Now loop back thru hyperlinks again and take the value in the label and use it to re create the hyperlink URLdestination for that hyperlink.
HJ
Copy link to clipboard
Copied
Hello,
Here is a lump of code I use to build a list of destinations and source.
//===================
var hypers = app.documents[0].hyperlinks.everyItem().getElements();
for ( len = 0; len < hypers.length; len++ )
{
// ===== START destinationURL
try
{
if (( hypers[len].destination ) && ( hypers[len].destination.hasOwnProperty("destinationURL")) && (hypers[len].destination.destinationURL.length ))
{
if ( hypers[len].source instanceof HyperlinkPageItemSource )
continue;
if ( 'undefined'==typeof hypers[len].source )
continue;
if ( 'undefined'==typeof hypers[len].source.sourceText )
continue;
if ( 'undefined'==typeof hypers[len].source.sourceText.parentTextFrames[0] )
continue;
if ( hypers[len].source.sourceText.contents.length )
{
hyperDesinations[nn] = {};
hyperDesinations[nn]["PARENT"] = hypers[len].source.sourceText.parentTextFrames[0];
hyperDesinations[nn]["id"] = hypers[len].source.sourceText.parentTextFrames[0].id;
hyperDesinations[nn]["TYPE"] = "URLDest";
hyperDesinations[nn]["SRC"] = hypers[len].source;
hyperDesinations[nn]["DEST"] = hypers[len].destination.destinationURL;
hyperDesinations[nn]["PARA"] = "";
nn++;
continue;
}
}
}
catch ( e ) {;}
Copy link to clipboard
Copied
Thanks Pickory - I'll probably use this code for another issue. As for this issue I ended up going with this solution:
1. Loop thru all hyperlinks and put a copy of the URLdestination text into the hyperlink label
2. Once all hyperlinks have been looped thru, delete all shared hyperlink URLdestinations
3. Now loop back thru hyperlinks again and take the value in the label and use it to re create the hyperlink URLdestination for that hyperlink.
Its probably not the fastest option in terms of performance but it was very easy to script : )
Here is an extract from my script for the above steps:
var myDoc=app.documents[0]
var myLinks=myDoc.hyperlinks.everyItem().getElements()
var myLinkDestinations = myDoc.hyperlinkURLDestinations.everyItem().getElements()
var myShareStatus
var myDestName = "www.xx.com"
var myDest
// 1. Loop thru all hyperlinks and put copy of the URL destination text in hyperlink label.
// Do only for hyperlinks that : (a) have a destination (b) is of destination type 'HyperlinkURLDestination'
// (c) the destination link contains 'www.xx.com' and (d) the destination link is shared
for(var i = myLinks.length-1; i>=0; i--)
{
// Have 'try' statement to bypass links that are broken/don't have a destination
try{
myShareStatus = myLinks.destination.hidden
if (myLinks.destination instanceof HyperlinkURLDestination && myShareStatus = "false" ){
if (myLinks.destination.destinationURL.indexOf('www.xx.com') >= 0){
// 2. If the hyperlink is shared, the hyperlink URL destination value needs to be added to the hyperlink label
if (myShareStatus = "false"){
myDest = myLinks.destination.destinationURL
myLinks.label = myDest
}
}
}
}
catch (err) {
//Do nothing
}
}
// 3. Loop thru hyperlink URLdestinations and delete any that are shared
for(var e = myLinkDestinations.length-1; e>=0; e--)
{
myShareStatus = myLinkDestinations
if (myLinkDestinations
myLinkDestinations
}
}
// 4. Loop thru hyperlinks and recreate hyperlink URLDestination from value in 'label' field.
//Only recreate URLDestination from 'label' if value in 'label' field contains www.xx.com
for(var i = myLinks.length-1; i>=0; i--)
{
if (myLinks.label.indexOf('www.xx.com') >= 0){
myDest = myLinks.label
myCounter = myCounter + 1
myDestName = myDestName + String(myCounter)
var myNewDest = myDoc.hyperlinkURLDestinations.add( myDest, {name:myDestName, hidden: true} );
myLinks.destination = myNewDest;
}
}
Copy link to clipboard
Copied
This should help some people:
1- Open HYPERLINKS window
2- Select all the hyperlinks you would like to UNCHECK their shared destination.
3- Double click on one of the hyperlinks you selected
4- When prompted, UNCHECK the shared destination box.
It will UNCHECK all that are selected.
Hope that helps.