• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Converting multiple phone numbers to hyperlinks/URL in InDesign all at once

New Here ,
Nov 09, 2016 Nov 09, 2016

Copy link to clipboard

Copied

I have a book that contains over 2,500 phone numbers that I update twice a year in InDesign and then export it into PDF. I just discovered a way for recipients of this PDF to save it to their iBooks app to then have the ability to access it from their mobile devices (iPhones, for the most part), where they can just click on a particular phone number and have their device automatically dial out to that number. Since there are SO many numbers provided in my book, is there an easy way to convert/program all of the numbers to essentially do the same function - call when clicked - all in one fell swoop, instead of converting each individual phone number into a hyperlink?  There has to be some code or script to accomplish this - can someone please help? Thanks!

Views

5.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 15, 2016 Dec 15, 2016

Here is a version of the script that adds a progress bar (which apparently doesn't always show on certain versions of Mac). In a clean new document with just 2,500 phone numbers the script runs almost a minute on my (almost new, well-specced) PC (in CC2015 and 2017). The progress bar shows that the script tears off furiously, then slows down after about 500 links, and crawls to the finish. But do try a test on a document with a few dozen numbers.

Peter

#targetengine phone_numbers;

(function () {

 

 

...

Votes

Translate

Translate
Community Beginner ,
Mar 04, 2020 Mar 04, 2020

Copy link to clipboard

Copied

I used the first one at the top, the one chosen as the correct answer. HEre it is:

#targetengine phone_numbers;

(function () {

  

  var i;

  var w;

  var cStyle;

  var found;

  var source;

  var destination;

  

  app.scriptPreferences.enableRedraw = true;

  

  try {

    app.panels.item('$ID/Hyperlinks').visible = false;

  } catch (_) {

  }

  if (!app.documents[0].characterStyles.item ('Hyperlink').isValid) {

    app.documents[0].characterStyles.add ({name: 'Hyperlink', underline: true});

  }

  cStyle = app.documents[0].characterStyles.item ('Hyperlink');

  app.findGrepPreferences = null;

  app.findGrepPreferences.findWhat = /\(\d\d\d\)\s\d\d\d-\d\d\d\d/.source;

  found = app.documents[0].findGrep();

  w = new Window ('palette {text: "Phone URLs"}');

    w.pbar = w.add ('progressbar', undefined, 0, found.length);

    w.pbar.preferredSize.width = 300;

  w.show();

  for (i = 0; i < found.length; i++) {

    w.pbar.value = i+1;

    source = app.documents[0].hyperlinkTextSources.add (found, {appliedCharacterStyle: cStyle});

    destination = app.documents[0].hyperlinkURLDestinations.add ({

      destinationURL: 'tel:' + found.contents.replace(/\D/g,'')

    });

    app.documents[0].hyperlinks.add (source, destination);

  }

  

  try {

    w.close();

  } catch (_) {

  }

}());

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2020 Mar 04, 2020

Copy link to clipboard

Copied

Spotted two errors that clearly were done by transferring this thread to the new forum.

Hope I found all. Try the code below; I did not test it:

 

 

 

#targetengine phone_numbers;

(function () {

	var i;
	var w;
	var cStyle;
	var found;
	var source;
	var destination;

	app.scriptPreferences.enableRedraw = true;

	try {
		app.panels.item('$ID/Hyperlinks').visible = false;
	} catch (_) {
	}

	if (!app.documents[0].characterStyles.item ('Hyperlink').isValid) {
		app.documents[0].characterStyles.add ({name: 'Hyperlink', underline: true});
	}

	cStyle = app.documents[0].characterStyles.item ('Hyperlink');

	app.findGrepPreferences = null;
	app.findGrepPreferences.findWhat = /\(\d\d\d\)\s\d\d\d-\d\d\d\d/.source;

	found = app.documents[0].findGrep();

	w = new Window ('palette {text: "Phone URLs"}');
	w.pbar = w.add ('progressbar', undefined, 0, found.length);
	w.pbar.preferredSize.width = 300;
	w.show();

	for (i = 0; i < found.length; i++) {
		w.pbar.value = i+1;
		source = app.documents[0].hyperlinkTextSources.add( found[i], {appliedCharacterStyle: cStyle} );

		destination = app.documents[0].hyperlinkURLDestinations.add ({
		destinationURL: 'tel:' + found[i].contents.replace(/\D/g,'')
		});

		app.documents[0].hyperlinks.add (source, destination);
	}


	try {
		w.close();
	} catch (_) {
	}

}());

 

 

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

Thank you for answering so quickly. Unfortunately, I'm getting the same error as before (error 30477 on line 59). Maybe I'm adding the file incorrectly--I just move it to the scripts panel folder and save it with a ".jsx" extension. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

Are you sure you copied the new code?
There is no line 59 in the script. The new code ends with line 52.

 

Regards,
Uwe Laubender

( ACP )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 05, 2020 Mar 05, 2020

Copy link to clipboard

Copied

THANK YOU THANK YOU THANK YOU THANK YOU

 

This is a miracle. I really appreciate it! It works great.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

I was able to get this to work as well. Thank you so much for taking the time to solve this challenge!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

Can someone please explain what's ".source" for in this line?

app.findGrepPreferences.findWhat = /\(\d\d\d\)\s\d\d\d-\d\d\d\d/.source

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2024 Jan 22, 2024

Copy link to clipboard

Copied

Hi @Thunder-Lightning ,

using .source is a different way to get that regular expression without declaring it explicitly as string.

With a string you'd have to escape every backslash with another backslash.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

Thanks for explaining that, I was wondering that myself...though, I have no scripting experience. I was getting an error on the earlier attempts and the error cited ".source" as part of the issue. Maybe someday I'll figure it all out! 🙂

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

LATEST

Thank you, @Laubender .

Is 'source' here referring to the variable?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2020 Dec 18, 2020

Copy link to clipboard

Copied

Hello, I've just tried to use the script and it seemed to work, even while I've changed the GREP search. But it doesn't work at all: it creates some phone URL, but that it stops with an error message (code error 79111) that says that the chosen object is yet in use for another hyperlink, or something like that (I'm italian and I'm using the italian version of Indesign, so I don't know how this code error is originally in english).

 

Could anyone help me? I'm not very experienced with scripts and similar things...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2024 Jan 23, 2024

Copy link to clipboard

Copied

Crealibro, if you face this issue again, you may want to make a duplicate copy of your document and remove all existing hyperlinks (you could even just duplicate a portion of the original document), then run it again. What may be happening is that an existing hyperlink is overlapped with the phone number (meaning, a portion of the phone number is part of that hyperlink, perhaps by accident). It could be that it happened due to a search and replace where you might not have known the hyperlink was formed that way. Also, if your hyperlinks all have a character style or paragraph style, you can search for a string like "(\d\d\d)" that has that style applied, and then see which of those is also part of an existing hyperlink. Drop that one into another doc, run the script on it, then paste it back into your original document. Just ideas...good luck!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines