Highlighted

active page vs selected page

Explorer ,
Jan 10, 2017

Copy link to clipboard

Copied

Hello to everyone!

I'm trying to find a way to get a reference to a page that is selected in Pages panel but not necessary is active one.

If I understand this correctly in the below example pages 2-3 are active even though page 4 is selected.

app.activeWindow.activePage - command will give reference to page number 2.

But what with page number 4? I can't find any method.

screen_pages.png

Thanks in advance,

jf

Adobe Community Professional
Correct answer by Laubender | Adobe Community Professional

Hi together,

 

below some code that is looking for active pages in the Pages panel where the property pageColor is exploited.

Since pageColor cannot be applied individuallly on pages on a given masterSpread—all pages on a master spread are colored the same, if you apply pageColor to a single page, one cannot detect if a single page on a master is selected in the Pages panel.

 

However, for selected document pages the function is working as it should.

 

Notes and some important issues:

1. The code below is overwriting already set values of pageColor. It's up to you to refine it.

2. In case of selected master pages, one cannot tell the exact page, only the spread.

3. If the "None" master is selected, it will return an empty array.

4. It's for CS6 and above, because the menu structure changed from CS5.5 to CS6.

But it would be easy to do a version for CS5 and CS5.5 as well, I think.

 

Tested with CC 2017 on Mac OSX 10.10.5, but should also run on Windows.

 

// CODE EDITED BECAUSE MOVING THIS THREAD TO THE NEW FORUM CHANGED THE CODE:

 

 

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v2.0.jsx !Version! Sun Jan 15 2017 14:10:32 GMT+0100
*/

/*
	
	1. ISSUE | If a single master page is selected, all pages of the master are stored as selected.
	2. ISSUE | The script will reset all pages' pageColor to: PageColorOptions.USE_MASTER_COLOR
	ToDo: 
	Get the initial state of pageColor for all pages and apply it again after retrieving the info.
	Or use several undos.
	
	3. ISSUE | CS6 and above
	
*/


// WARNING :
// With CS5 and CS5.5 there are different menu hierarchies
// NOT IMPLEMENTED HERE!!
// But basically the trick should work with CS5 and CS5.5 as well.

// THIS ONE IS FOR CS6 and ABOVE:

// Full code variation in:
// GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx



/*
// Core functionality:

app.menus.item("$ID/PagesPanelPopup").
	submenus.itemByName("$ID/PageAttributesSubMenu").
	submenus.itemByName("$ID/PageColorLabelMenu").
	menuItems[-1].associatedMenuAction.invoke();
*/
	
// VERSION 1 working with CS6 ONLY:

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx !Version! Fri Jan 13 2017 11:41:41 GMT+0100
*/

/*
	Script by Uwe Laubender published at Adobe InDesign Scripting forum:
	
	active page vs selected page
	Jarek Foltman Jan 10, 2017
	https://forums.adobe.com/message/9251733#9251733
	
*/

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

app.doScript
	(
	
	addTextFrameToSelectedPagesInThePagesPanel, 
	ScriptLanguage.JAVASCRIPT, 
	[],
	UndoModes.ENTIRE_SCRIPT, 
	"Add text frame to the selected pages in the Pages panel | SCRIPT"
	
	);

// USE CASE EXAMPLE:

function addTextFrameToSelectedPagesInThePagesPanel()
{

	if(parseInt(app.version) < 8 )
	{
		alert
		(
			"SORRY:"+"\r"+
			"This is script can ONLY work with InDesign CS6 and later."
		);
		return
	}
	
	var doc = app.documents[0];
	var selectedPagesArray = getSelectedPagesInPagesPanel();

	for(var n=0;n<selectedPagesArray.length;n++)
	{
		var textFrame = selectedPagesArray[n].textFrames.add
		(
			{
				geometricBounds : selectedPagesArray[n].bounds ,
				fillColor : doc.colors.itemByName("Yellow") ,
				strokeColor : "None" ,
				contents : "Selected in Pages panel."
			}
		)
		textFrame.texts[0].pointSize = 80;
		textFrame.texts[0].justification = Justification.CENTER_ALIGN;
		textFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
	}

};

// Will return empty array or array with pages
// Could be pages of master spreads or document pages

function getSelectedPagesInPagesPanel()
{
	var resultArray = [];
	
	if(app.documents.length == 0){return resultArray };
	
	// What happens, if the Pages panel is closed?
	// Is the selection of pages still valid?
	
	// RESULT AFTER TESTING:
	// If the Pages panel is closed, after opening it again, the first page of the document is always selected.
	// So it's best I think to do nothing if the Pages panel is closed.
	// Return empty array:
	
	 if(!app.panels.itemByName("$ID/Pages").visible){return resultArray };
	
	var doc = app.documents[0];
	
	doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	doc.pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;

	try
	{
	app.menus.item("$ID/PagesPanelPopup").
		submenus.itemByName("$ID/PageAttributesSubMenu").
		submenus.itemByName("$ID/PageColorLabelMenu").
		menuItems[-1].associatedMenuAction.invoke();
	}catch(e)
	{
		// Master "None" selected in the Pages Panel
		return resultArray;
	}
		
	var masterPages = doc.masterSpreads.everyItem().pages.everyItem().getElements();
	var masterPagesLength = masterPages.length;
	var docPages = doc.pages.everyItem().getElements();
	var docPagesLength = docPages.length;

	// Master pages first:

	for(var n=0;n<masterPagesLength;n++)
	{
		if(masterPages[n].pageColor != 1346594413)
		{
			resultArray[resultArray.length++] = masterPages[n];
		};
	
		// $.writeln(n+"\t"+"master | pageColor"+"\t"+masterPages[n].pageColor.toString() );
	};

	// Then document pages:
	
	for(var n=0;n<docPagesLength;n++)
	{
		if(docPages[n].pageColor != 1346594413)
		{
			resultArray[resultArray.length++] = docPages[n];
		};
	
		// $.writeln(n+"\t"+"doc | pageColor"+"\t"+docPages[n].pageColor.toString() );
	
	};
	
	doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	doc.pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	
	return resultArray;

};

 

 

Regards,
Uwe

Topics

Scripting

Views

4.3K

Likes

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

active page vs selected page

Explorer ,
Jan 10, 2017

Copy link to clipboard

Copied

Hello to everyone!

I'm trying to find a way to get a reference to a page that is selected in Pages panel but not necessary is active one.

If I understand this correctly in the below example pages 2-3 are active even though page 4 is selected.

app.activeWindow.activePage - command will give reference to page number 2.

But what with page number 4? I can't find any method.

screen_pages.png

Thanks in advance,

jf

Adobe Community Professional
Correct answer by Laubender | Adobe Community Professional

Hi together,

 

below some code that is looking for active pages in the Pages panel where the property pageColor is exploited.

Since pageColor cannot be applied individuallly on pages on a given masterSpread—all pages on a master spread are colored the same, if you apply pageColor to a single page, one cannot detect if a single page on a master is selected in the Pages panel.

 

However, for selected document pages the function is working as it should.

 

Notes and some important issues:

1. The code below is overwriting already set values of pageColor. It's up to you to refine it.

2. In case of selected master pages, one cannot tell the exact page, only the spread.

3. If the "None" master is selected, it will return an empty array.

4. It's for CS6 and above, because the menu structure changed from CS5.5 to CS6.

But it would be easy to do a version for CS5 and CS5.5 as well, I think.

 

Tested with CC 2017 on Mac OSX 10.10.5, but should also run on Windows.

 

// CODE EDITED BECAUSE MOVING THIS THREAD TO THE NEW FORUM CHANGED THE CODE:

 

 

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v2.0.jsx !Version! Sun Jan 15 2017 14:10:32 GMT+0100
*/

/*
	
	1. ISSUE | If a single master page is selected, all pages of the master are stored as selected.
	2. ISSUE | The script will reset all pages' pageColor to: PageColorOptions.USE_MASTER_COLOR
	ToDo: 
	Get the initial state of pageColor for all pages and apply it again after retrieving the info.
	Or use several undos.
	
	3. ISSUE | CS6 and above
	
*/


// WARNING :
// With CS5 and CS5.5 there are different menu hierarchies
// NOT IMPLEMENTED HERE!!
// But basically the trick should work with CS5 and CS5.5 as well.

// THIS ONE IS FOR CS6 and ABOVE:

// Full code variation in:
// GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx



/*
// Core functionality:

app.menus.item("$ID/PagesPanelPopup").
	submenus.itemByName("$ID/PageAttributesSubMenu").
	submenus.itemByName("$ID/PageColorLabelMenu").
	menuItems[-1].associatedMenuAction.invoke();
*/
	
// VERSION 1 working with CS6 ONLY:

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx !Version! Fri Jan 13 2017 11:41:41 GMT+0100
*/

/*
	Script by Uwe Laubender published at Adobe InDesign Scripting forum:
	
	active page vs selected page
	Jarek Foltman Jan 10, 2017
	https://forums.adobe.com/message/9251733#9251733
	
*/

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

app.doScript
	(
	
	addTextFrameToSelectedPagesInThePagesPanel, 
	ScriptLanguage.JAVASCRIPT, 
	[],
	UndoModes.ENTIRE_SCRIPT, 
	"Add text frame to the selected pages in the Pages panel | SCRIPT"
	
	);

// USE CASE EXAMPLE:

function addTextFrameToSelectedPagesInThePagesPanel()
{

	if(parseInt(app.version) < 8 )
	{
		alert
		(
			"SORRY:"+"\r"+
			"This is script can ONLY work with InDesign CS6 and later."
		);
		return
	}
	
	var doc = app.documents[0];
	var selectedPagesArray = getSelectedPagesInPagesPanel();

	for(var n=0;n<selectedPagesArray.length;n++)
	{
		var textFrame = selectedPagesArray[n].textFrames.add
		(
			{
				geometricBounds : selectedPagesArray[n].bounds ,
				fillColor : doc.colors.itemByName("Yellow") ,
				strokeColor : "None" ,
				contents : "Selected in Pages panel."
			}
		)
		textFrame.texts[0].pointSize = 80;
		textFrame.texts[0].justification = Justification.CENTER_ALIGN;
		textFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
	}

};

// Will return empty array or array with pages
// Could be pages of master spreads or document pages

function getSelectedPagesInPagesPanel()
{
	var resultArray = [];
	
	if(app.documents.length == 0){return resultArray };
	
	// What happens, if the Pages panel is closed?
	// Is the selection of pages still valid?
	
	// RESULT AFTER TESTING:
	// If the Pages panel is closed, after opening it again, the first page of the document is always selected.
	// So it's best I think to do nothing if the Pages panel is closed.
	// Return empty array:
	
	 if(!app.panels.itemByName("$ID/Pages").visible){return resultArray };
	
	var doc = app.documents[0];
	
	doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	doc.pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;

	try
	{
	app.menus.item("$ID/PagesPanelPopup").
		submenus.itemByName("$ID/PageAttributesSubMenu").
		submenus.itemByName("$ID/PageColorLabelMenu").
		menuItems[-1].associatedMenuAction.invoke();
	}catch(e)
	{
		// Master "None" selected in the Pages Panel
		return resultArray;
	}
		
	var masterPages = doc.masterSpreads.everyItem().pages.everyItem().getElements();
	var masterPagesLength = masterPages.length;
	var docPages = doc.pages.everyItem().getElements();
	var docPagesLength = docPages.length;

	// Master pages first:

	for(var n=0;n<masterPagesLength;n++)
	{
		if(masterPages[n].pageColor != 1346594413)
		{
			resultArray[resultArray.length++] = masterPages[n];
		};
	
		// $.writeln(n+"\t"+"master | pageColor"+"\t"+masterPages[n].pageColor.toString() );
	};

	// Then document pages:
	
	for(var n=0;n<docPagesLength;n++)
	{
		if(docPages[n].pageColor != 1346594413)
		{
			resultArray[resultArray.length++] = docPages[n];
		};
	
		// $.writeln(n+"\t"+"doc | pageColor"+"\t"+docPages[n].pageColor.toString() );
	
	};
	
	doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	doc.pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	
	return resultArray;

};

 

 

Regards,
Uwe

Topics

Scripting

Views

4.3K

Likes

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
LEGEND ,
Jan 10, 2017

Copy link to clipboard

Copied

Panel interaction is perhaps the weakest area in InDesign scripting. I don't think there's a way to get the selected pages in the Pages Panel.

Likes

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
Reply
Loading...
Explorer ,
Jan 11, 2017

Copy link to clipboard

Copied

Phew!

Thanks, I thought so.

I'll try to find a way around it.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jan 13, 2017

Copy link to clipboard

Copied

Hi Jarek,

I see a good chance for InDesign CS6 only where you can get the selected pages in the Pages panel.

For all other versions of InDesign—before and after CS6—there is a way to get the selected pages, but it comes with some severe problems. See the list below where I discuss this.

The solution is revolving around using menu commands with the Pages panel.

InDesign CS6 only:

Menu command with the key string:

"$ID/kOptionalPageMenuItem".

In my German version of CS6, this menu command is named:

"Optional in Liquid-HTML5".

What does "Optional in Liquid-HTML5" do?

It applies true or false to the page property optionalPage.

optionalPage was part of an experimental feature with InDesign's EPUB export function (as far as I remember) and is not implemented with all other versions of InDesign but CS6.

How could we use this feature?

You can check the value of optionalPage on every page and master page ( not the "None" master ) in the document before using the menu command and after using it. Therfore you can retrieve the selected pages in the Pages panel. If master "None" is selected one cannot use the menu command. We could detect this case by using try/catch for instance.

All other versions of InDesign:

For all other versions—where unfortunately "$ID/kOptionalPageMenuItem" is not available—one of the following three instances of the same menu command can be used. Depending on what exactly is selected.

"$ID/kDuplicatePageCmd" (German: "Seite duplizieren")

"$ID/kDuplicatePagesCmd" (German: "Seiten duplizieren")

"$ID/kDuplicateSpreadCmd" (German: "Druckbogen duplizieren")

There are other menu command strings available if you select master pages or all pages on a master.
Or one could use the menu command for removing pages. I did not fully test all the options available.

Problems are:

1. You have to undo what you did with the menu command.

2. If you undo the duplicating of the document pages:

2.1 The selection in the Pages panel is lost.

2.2 The active page will be a different one.

3. I had trouble—means was not able, not tested all ideas—to find the relevant locale-agnostic keystrings if all the pages of a master spread are selected.

No save bet:

Using the index of the menu commands to execute the associatedMenuAction.

3rd-party scripts or plug-in could have installed other menu commands in the list before the one you are trying to use.

Regards,
Uwe

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jan 13, 2017

Copy link to clipboard

Copied

Here some code for InDesign CS6 only where I exploit property optionalPage of the Page object:

 

// CODE EDITED BECAUSE MOVING THIS THREAD TO THE NEW FORUM CHANGED THE CODE:

 

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx !Version! Fri Jan 13 2017 11:41:41 GMT+0100
*/

/*
	Script published at Adobe InDesign Scripting forum:
	
	active page vs selected page
	Jarek Foltman Jan 10, 2017
	https://forums.adobe.com/message/9251733#9251733
	
*/

// CS6 ONLY !!
// Example usage:

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

app.doScript
	(
	
	addTextFrameToSelectedPagesInThePagesPanel, 
	ScriptLanguage.JAVASCRIPT, 
	[],
	UndoModes.ENTIRE_SCRIPT, 
	"Add text frame to the selected pages in the Pages panel | SCRIPT"
	
	);

// USE CASE EXAMPLE:

function addTextFrameToSelectedPagesInThePagesPanel()
{

	if(parseInt(app.version) != 8 )
	{
		alert
		(
			"SORRY:"+"\r"+
			"This is script can ONLY work with InDesign CS6."
		);
		return
	}
	
	var doc = app.documents[0];
	var selectedPagesArray = getSelectedPagesInPagesPanel();

	for(var n=0;n<selectedPagesArray.length;n++)
	{
		var textFrame = selectedPagesArray[n].textFrames.add
		(
			{
				geometricBounds : selectedPagesArray[n].bounds ,
				fillColor : doc.colors.itemByName("Yellow") ,
				strokeColor : "None" ,
				contents : "Selected in Pages panel."
			}
		)
		textFrame.texts[0].pointSize = 80;
		textFrame.texts[0].justification = Justification.CENTER_ALIGN;
		textFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
	}

};

// Will return empty array or array with pages
// Could be pages of master spreads or document pages

function getSelectedPagesInPagesPanel()
{
	var resultArray = [];
	
	if(app.documents.length == 0){return resultArray };
	
	// What happens, if the Pages panel is closed?
	// Is the selection of pages still valid?
	
	// RESULT AFTER TESTING:
	// If the Pages panel is closed, after opening it again, the first page of the document is always selected.
	// So it's best I think to do nothing if the Pages panel is closed.
	// Return empty array:
	
	 if(!app.panels.itemByName("$ID/Pages").visible){return resultArray };
	
	var doc = app.documents[0];
	var oldOptionalPages = app.documents[0].pages.everyItem().optionalPage;
	var oldOptionalMasterPages = app.documents[0].masterSpreads.everyItem().pages.everyItem().optionalPage;

	var docPages = doc.pages.everyItem().getElements();
	var masterPages = doc.masterSpreads.everyItem().pages.everyItem().getElements();

	doc.pages.everyItem().optionalPage = false;
	doc.masterSpreads.everyItem().pages.everyItem().optionalPage = false;

	try
	{
	app.menus.item("$ID/PagesPanelPopup").
		submenus.itemByName("$ID/PageAttributesSubMenu").
		menuItems.itemByName("$ID/kOptionalPageMenuItem").
		associatedMenuAction.invoke();
	}catch(e)
	{
		// Master "None" selected in the Pages Panel
		return resultArray;
	}
		
	var optionalPages = app.documents[0].pages.everyItem().optionalPage;
	var optionalPagesLength = optionalPages.length;

	var optionalMasterPages = app.documents[0].masterSpreads.everyItem().pages.everyItem().optionalPage;
	var optionalMasterPagesLength = optionalMasterPages.length;

	for(var n=0;n<optionalPagesLength;n++)
	{
		if(optionalPages[n] == true)
		{
			resultArray[resultArray.length++] = docPages[n];
		};
		// Reset the old value:
		docPages[n].optionalPage = oldOptionalPages[n];
	};

	for(var n=0;n<optionalMasterPagesLength;n++)
	{
		if(optionalMasterPages[n] == true)
		{
			resultArray[resultArray.length++] = masterPages[n];
		};
		// Reset the old value:
		masterPages[n].optionalPage = oldOptionalMasterPages[n];
	};
	
	return resultArray;

};

 

Some screenshots:

 

Case A, document pages selected in the Pages panel.

Before running the script:

 

1-DocumentPagesSelected.png

 

After running the script:

 

2-DocumentPagesSelected-AfterScriptRun.png

 

 

Case B, master pages selected in the Pages panel.

Before running the script:

 

3-MasterPagesSelected.png

 

After running the script:

 

4-MasterPagesSelected-AfterScriptRun.png

 

Regards,
Uwe

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jan 13, 2017

Copy link to clipboard

Copied

Here another idea for none-CS6 versions above CS5 (edit: AND also for CS6):

We could try to reach and execute the menu command for page labels and compare the state of labels before and after invoking the menu. That possibly would not affect the selection state of the selected pages in the Pages panel.

Regards,
Uwe

//EDITED

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jan 15, 2017

Copy link to clipboard

Copied

Hi together,

 

below some code that is looking for active pages in the Pages panel where the property pageColor is exploited.

Since pageColor cannot be applied individuallly on pages on a given masterSpread—all pages on a master spread are colored the same, if you apply pageColor to a single page, one cannot detect if a single page on a master is selected in the Pages panel.

 

However, for selected document pages the function is working as it should.

 

Notes and some important issues:

1. The code below is overwriting already set values of pageColor. It's up to you to refine it.

2. In case of selected master pages, one cannot tell the exact page, only the spread.

3. If the "None" master is selected, it will return an empty array.

4. It's for CS6 and above, because the menu structure changed from CS5.5 to CS6.

But it would be easy to do a version for CS5 and CS5.5 as well, I think.

 

Tested with CC 2017 on Mac OSX 10.10.5, but should also run on Windows.

 

// CODE EDITED BECAUSE MOVING THIS THREAD TO THE NEW FORUM CHANGED THE CODE:

 

 

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v2.0.jsx !Version! Sun Jan 15 2017 14:10:32 GMT+0100
*/

/*
	
	1. ISSUE | If a single master page is selected, all pages of the master are stored as selected.
	2. ISSUE | The script will reset all pages' pageColor to: PageColorOptions.USE_MASTER_COLOR
	ToDo: 
	Get the initial state of pageColor for all pages and apply it again after retrieving the info.
	Or use several undos.
	
	3. ISSUE | CS6 and above
	
*/


// WARNING :
// With CS5 and CS5.5 there are different menu hierarchies
// NOT IMPLEMENTED HERE!!
// But basically the trick should work with CS5 and CS5.5 as well.

// THIS ONE IS FOR CS6 and ABOVE:

// Full code variation in:
// GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx



/*
// Core functionality:

app.menus.item("$ID/PagesPanelPopup").
	submenus.itemByName("$ID/PageAttributesSubMenu").
	submenus.itemByName("$ID/PageColorLabelMenu").
	menuItems[-1].associatedMenuAction.invoke();
*/
	
// VERSION 1 working with CS6 ONLY:

/**
* @@@BUILDINFO@@@ GetPages-SELECTED-IN-PAGES-PANEL-v1.0.jsx !Version! Fri Jan 13 2017 11:41:41 GMT+0100
*/

/*
	Script by Uwe Laubender published at Adobe InDesign Scripting forum:
	
	active page vs selected page
	Jarek Foltman Jan 10, 2017
	https://forums.adobe.com/message/9251733#9251733
	
*/

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

app.doScript
	(
	
	addTextFrameToSelectedPagesInThePagesPanel, 
	ScriptLanguage.JAVASCRIPT, 
	[],
	UndoModes.ENTIRE_SCRIPT, 
	"Add text frame to the selected pages in the Pages panel | SCRIPT"
	
	);

// USE CASE EXAMPLE:

function addTextFrameToSelectedPagesInThePagesPanel()
{

	if(parseInt(app.version) < 8 )
	{
		alert
		(
			"SORRY:"+"\r"+
			"This is script can ONLY work with InDesign CS6 and later."
		);
		return
	}
	
	var doc = app.documents[0];
	var selectedPagesArray = getSelectedPagesInPagesPanel();

	for(var n=0;n<selectedPagesArray.length;n++)
	{
		var textFrame = selectedPagesArray[n].textFrames.add
		(
			{
				geometricBounds : selectedPagesArray[n].bounds ,
				fillColor : doc.colors.itemByName("Yellow") ,
				strokeColor : "None" ,
				contents : "Selected in Pages panel."
			}
		)
		textFrame.texts[0].pointSize = 80;
		textFrame.texts[0].justification = Justification.CENTER_ALIGN;
		textFrame.textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN;
	}

};

// Will return empty array or array with pages
// Could be pages of master spreads or document pages

function getSelectedPagesInPagesPanel()
{
	var resultArray = [];
	
	if(app.documents.length == 0){return resultArray };
	
	// What happens, if the Pages panel is closed?
	// Is the selection of pages still valid?
	
	// RESULT AFTER TESTING:
	// If the Pages panel is closed, after opening it again, the first page of the document is always selected.
	// So it's best I think to do nothing if the Pages panel is closed.
	// Return empty array:
	
	 if(!app.panels.itemByName("$ID/Pages").visible){return resultArray };
	
	var doc = app.documents[0];
	
	doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	doc.pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;

	try
	{
	app.menus.item("$ID/PagesPanelPopup").
		submenus.itemByName("$ID/PageAttributesSubMenu").
		submenus.itemByName("$ID/PageColorLabelMenu").
		menuItems[-1].associatedMenuAction.invoke();
	}catch(e)
	{
		// Master "None" selected in the Pages Panel
		return resultArray;
	}
		
	var masterPages = doc.masterSpreads.everyItem().pages.everyItem().getElements();
	var masterPagesLength = masterPages.length;
	var docPages = doc.pages.everyItem().getElements();
	var docPagesLength = docPages.length;

	// Master pages first:

	for(var n=0;n<masterPagesLength;n++)
	{
		if(masterPages[n].pageColor != 1346594413)
		{
			resultArray[resultArray.length++] = masterPages[n];
		};
	
		// $.writeln(n+"\t"+"master | pageColor"+"\t"+masterPages[n].pageColor.toString() );
	};

	// Then document pages:
	
	for(var n=0;n<docPagesLength;n++)
	{
		if(docPages[n].pageColor != 1346594413)
		{
			resultArray[resultArray.length++] = docPages[n];
		};
	
		// $.writeln(n+"\t"+"doc | pageColor"+"\t"+docPages[n].pageColor.toString() );
	
	};
	
	doc.masterSpreads.everyItem().pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	doc.pages.everyItem().pageColor = PageColorOptions.USE_MASTER_COLOR;
	
	return resultArray;

};

 

 

Regards,
Uwe

Likes

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
Reply
Loading...
Explorer ,
Jan 17, 2017

Copy link to clipboard

Copied

Wow, Uwe, that one is great! It is exactly what I was looking for.

I'm digging into it right now, making modifications needed for my purpose.

I would newer thought about exploring color label properties.

Thank you very much!

Jarek

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jan 17, 2017

Copy link to clipboard

Copied

Hi Jarek,

the one for InDesign CS6 only is more insteresting, because it can detect also selected master pages, but unfortunately the menu I exploited for that is not available anymore in higher versions.

Cheers,

Uwe

Likes

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
Reply
Loading...
Explorer ,
Jan 18, 2017

Copy link to clipboard

Copied

Hello Uwe!

I've noticed that in cc you can only apply label to whole master spread, not to single page. But even with this limitation your method works very well.

So once again thanks for it.

Best,

Jarek

Likes

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
Reply
Loading...
Engaged ,
Sep 26, 2019

Copy link to clipboard

Copied

Thanks for this! I'm writing something similar based on this for selected pages, but if I invoke the pageColor with none selected it colors the page anyway, which I could turn into a feature rather than a flaw, but I'm wondering how to weed out the activePage if it's not meant to be selected, and is only active. One workaround I can try is by creating a Master page, activating it, analyzing the pages highlighted, deleting the master page, and reactivating the original page. I'm otherwise wondering if there is a more direct way?

Likes

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
Reply
Loading...
Enthusiast ,
Dec 05, 2019

Copy link to clipboard

Copied

Thank you, Uwe, for this clever workaround! It's sad that Adobe has no recommended way to determine selected pages.

It seems all your [n] loop parameters are missing in the script example. Perhaps they were destroyed in the forum update some months ago? Here are the changes I made to test your example, and then it ran perfectly. Tested in CC2018 and CC2019 as well.

Capture1.PNG

 

Likes

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
Reply
Loading...
Adobe Community Professional ,
Dec 05, 2019

Copy link to clipboard

Copied

Hi Andreas,

about the [n] loop parameters. Yes!!! Very likely the forum update or the migration process of threads destroyed them. I've seen this in several posts. Another bug to report ( sigh! ). Something that makes posted scripts unusable for non-script writers. The more I think of this the more I get really, really angry. And sad.

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Adobe Employee ,
Dec 09, 2019

Copy link to clipboard

Copied

Hi Uwe,

 

The forums team is rolling out updates every two weeks with bug fixes. I'll make sure this gets on the list of bugs.

 

Best,

Erin F.

Community Engineer, Creative Cloud

Likes

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
Reply
Loading...
Adobe Community Professional ,
Dec 10, 2019

Copy link to clipboard

Copied

Hi Erin,

now I edited the code above and hope that it will work as before.

 

Replies:

 

https://community.adobe.com/t5/indesign/active-page-vs-selected-page/m-p/8776565#M35095

https://community.adobe.com/t5/indesign/active-page-vs-selected-page/m-p/8776563#M35093

 

Regards,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
ErinF LATEST
Adobe Employee ,
Dec 12, 2019

Copy link to clipboard

Copied

Hi Uwe, I have reported this as bug ALFD-2002 internally.

 

As we bring back more scripts from the archive it's important that this get fixed.

Likes

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
Reply
Loading...