Skip to main content
rickt38612460
Known Participant
December 14, 2022
Answered

Script to use link name in search URL

  • December 14, 2022
  • 1 reply
  • 570 views

I have noe experience with javascript but would like to create a script for Indesign that would get the link file name of the selection apply some  GREP to the result, grabbing part of the link name, then use the result in a search URL which would open in the browser.

 

Example

With a frame selected in Indesign with an image inside with example file name below 1234567_00000000000000.jpg fileName

 

I think the below javascript will grab the file name but I dont know how to use this into a variable.

app.selection[0].graphics[0].itemLink.name;

 

Then use the below GREP to grab the first 7 digitits

\<\d\d\d\d\d\d\d fileName7

and pass that into a search URL and open in a browser

https://website.pretend.com/UserSearchResult.php/media_search%5BsSimpleSearchString%5D=fileName7&media=simple

 

Is any one able to help turn this into a Indesign javascript?

 

 

 

This topic has been closed for replies.
Correct answer Manan Joshi

Hi @rickt38612460,

Try the following

var itemName = app.selection[0].graphics[0].itemLink.name;
var url = "https://website.pretend.com/UserSearchResult.php/media_search%5BsSimpleSearchString%5D="
var fn = itemName.match(/^\d{7}/)
if(fn){
	url += fn[0] + "&media=simple" 
	var a = app.documents[0].hyperlinkURLDestinations.add(url)
	a.showDestination()
}

-Manan

1 reply

Manan JoshiCommunity ExpertCorrect answer
Community Expert
December 15, 2022

Hi @rickt38612460,

Try the following

var itemName = app.selection[0].graphics[0].itemLink.name;
var url = "https://website.pretend.com/UserSearchResult.php/media_search%5BsSimpleSearchString%5D="
var fn = itemName.match(/^\d{7}/)
if(fn){
	url += fn[0] + "&media=simple" 
	var a = app.documents[0].hyperlinkURLDestinations.add(url)
	a.showDestination()
}

-Manan

-Manan
rickt38612460
Known Participant
December 15, 2022

Thanks @Manan Joshi that works perfectly.

Your time, help and expertise are much apreciated!