Skip to main content
johnpredmore
Inspiring
June 20, 2018
Question

Add Subject Line to Email Hyperlink

  • June 20, 2018
  • 1 reply
  • 1590 views

I'm trying to script the application of a hyperlink to email from a character style. I've managed to make it work for the most part but now I'm at a loss about how to modify the Subject Line in the hyperlink that is created. Any ideas?

var myDoc = app.activeDocument; 

app.findGrepPreferences = app.changeGrepPreferences = null; 

 

app.findGrepPreferences.findWhat = ".+"; 

app.findGrepPreferences.appliedCharacterStyle = "Email Hyperlink"; 

var myFound1 = myDoc.findGrep(); 

 

count = 0 

for(k=0; k<myFound1.length; k++) 

try{ 

    var myFind = myFound1

    var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(myFound1); 

    var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations.add("mailto:"+myFound1.contents);

    var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkURLDestination, {name: myFound1.contents+count++}); 

    count++ 

}catch(e){} 

 

alert(count/2 + " E-Mail Hyperlinks Created"); 

This topic has been closed for replies.

1 reply

Loic.Aigon
Legend
June 21, 2018
johnpredmore
Inspiring
June 21, 2018

Hi Loic, thanks; that worked. Is there a way to dynamically pull the name of a document, so that it becomes part of the subject field?

For example, I have a 100 documents, each about a product offering. If one of those documents is called coffee.indd, is there a way I can pull that part through scripting, and add it to a static part so my subject might be something like New Offerings Coffee?

Loic.Aigon
Legend
June 21, 2018

doc.hyperlinkURLDestinations.add('mailto:loic.aigon@ozalto.com?subject='+doc.name);