Copy link to clipboard
Copied
Hi Scripters,
Another issue about hyperlinks!
As shown in the screenshot below, destinations are missing! So, the deal is to remove the concerned hyperlinks!
I wrote this code but it doesn't work!
var myDoc = app.activeDocument;
var myHyperlinks = myDoc.hyperlinks.everyItem().getElements();
for ( H = 0; H < myHyperlinks.length; H++ )
{
var myDestination = myHyperlinks
.HyperlinkTextDestination.destinationText; if ( !myDestination.isvalid ) myHyperlinks
.remove(); }
Thanks in advance for your help!
(^/)
Hi Obi,
If you are looking for improvements, you may want to :
1) Include you code into a function to reduce global scope variables. The more global variables you have the slower your script will go.
2) Check object references validity. your script may throw an error if the script is run without any open document.
3) Use a reference to the array length instead of reading the property every loop
4) Besides you do not need to transform the collection into an array here as you don't take advantage of an
...Copy link to clipboard
Copied
Fixed!
var myDoc = app.activeDocument;
var myHyperlinks = myDoc.hyperlinks.everyItem().getElements();
for ( H = 0; H < myHyperlinks.length; H++ )
{
var myDestination = myHyperlinks
.destination; if ( myDestination == null ) myHyperlinks
.remove(); }
(^/)
Copy link to clipboard
Copied
Hi Obi,
If you are looking for improvements, you may want to :
1) Include you code into a function to reduce global scope variables. The more global variables you have the slower your script will go.
2) Check object references validity. your script may throw an error if the script is run without any open document.
3) Use a reference to the array length instead of reading the property every loop
4) Besides you do not need to transform the collection into an array here as you don't take advantage of any specific array only function such as sorting, slicing, concatening…
So you script could have been:
var main = function() {
var d = app.properties.activeDocument,
hs, h, ds, n = 0;
if ( !d) return;
hs = d.hyperlinks, n = hs.length;
while ( n-- ) {
h = hs
; ds = h.properties.destination;
!ds && h.remove();
}
}
main();
HTH
Loic
Copy link to clipboard
Copied
Hi Loïc,
Nice code and interesting writing!
Even if mine works, I indicate it as "correct"! Sample to be followed!
I take it! Thanks!
(^/)