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

Javascript dialog box – return result into variable

Explorer ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Hi 

I have a script that will search the document and capture all of the hyperlink text destinations and put them into a variable. I then create a dialog box that will popup and create a list of options using the previously captured hyperlink text destinations so the user can select which one they want to use in the next part of the script. It looks like this.

Screen Shot 2022-02-21 at 9.58.41 pm.png

 

I am having trouble being able to get the script to return to me which text destination the user has selected.

My script so far is below:

 

var doc = app.activeDocument;

//list every hyperlink text destination in the document.
var hlinks = doc.hyperlinkTextDestinations.everyItem().name;


//open a new dialog box.
var myWindow = new Window ("dialog");
var myInputGroup = myWindow.add ("group");
//add a list using the array of hyperlinks
var myList = myWindow.add ("listbox", undefined, hlinks);
myList.selection = 0;


var myButtonGroup = myWindow.add ("group");
 myButtonGroup.alignment = "right";
 myButtonGroup.add ("button", undefined, "OK");
 myButtonGroup.add ("button", undefined, "Cancel");
var myResult = myWindow.show ();

if ( myResult==1 ) {

        alert( "I selected:"+myList.contents);

    }

 

Any help or pointing in the right direction would be greatly appreciated!

Thanks.

TOPICS
Scripting

Views

330

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

Guru , Feb 21, 2022 Feb 21, 2022

 

main();

function main() {
	var doc = app.activeDocument;

	//list every hyperlink text destination in the document.
	var hlinks = doc.hyperlinkPageDestinations.everyItem().name;
	
	
	//open a new dialog box.
	var myWindow = new Window ("dialog");
	var myInputGroup = myWindow.add ("group");
	//add a list using the array of hyperlinks
	var myList = myWindow.add ("listbox", undefined, hlinks);
	myList.selection = 0;
	
	
	var myButtonGroup = myWindow.add ("group");
	 myButtonGroup.alignment = "rig
...

Votes

Translate

Translate
Guru ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

 

main();

function main() {
	var doc = app.activeDocument;

	//list every hyperlink text destination in the document.
	var hlinks = doc.hyperlinkPageDestinations.everyItem().name;
	
	
	//open a new dialog box.
	var myWindow = new Window ("dialog");
	var myInputGroup = myWindow.add ("group");
	//add a list using the array of hyperlinks
	var myList = myWindow.add ("listbox", undefined, hlinks);
	myList.selection = 0;
	
	
	var myButtonGroup = myWindow.add ("group");
	 myButtonGroup.alignment = "right";
	 myButtonGroup.add ("button", undefined, "OK");
	 myButtonGroup.add ("button", undefined, "Cancel");
	var myResult = myWindow.show ();
	
	if ( myResult==1 ) {
	
			alert( "I selected: " + myList.selection.text);
	
		}
}

Looking at your screenshot I assume you mean page destinations.

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Hi @Kasyan Servetsky, I think the screen shot doesn't quite represent how Iwill be using it but I do mean Hyperlink Text Destinations. I made a test document as a simplified version and wrote in Page X so it would be easy to test if the Hyperlinks are working.

I am making a script that will help me in producing a recipe book. I have the first script that will find all of the recipe names (via the paragraph style) and turn them into Hyperlink Text Destinations of the same name as the recipe.

 

The script I am trying to write now will be for other parts of the book where I want to refer back to another recipe – lets say I am on the recipe for pizza, I might have some words refereing back to the recipe for how to make the dough. 

I want to do it with Hyperlink Text destinations because it isn't uncommon for the page numbers to change or the order of the recipes to move around.

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

LATEST

I think what I was missing was your addition of the selection.text in the section below.

myList.selection.text

 I altered the original and it seems to be giving me the result I want

Thanks for your help @Kasyan Servetsky 

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