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

InDesign 2020 Automation (My workflow and questions) - Scripting

New Here ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

Hello wonderful forum folks,

 

I have been a long time user of adobe and read much on the forums, however I am new to indesign. My world was previously After Effects and Premier. Due to a number of buisness changes I am now learning scripting for InDesign.

 

What I have so far.

For the past 20 or so years our organization has been manually copying over schedules from our bus scheduling app into indesign and formatting them all by hand. (Crazy I know)

 

When I was brought onto the team I kinda looked at it and went Huh? Why?

 

The Scheduling application has a bulky but wonderful XML output for schedules so what do I do XML import and match to table cells and poof we have auto updatable scheduling. However they want everything in AM and PM with PM times bolded to show they are PM and of course the schedule is in 24hr time. Cool so I learn the basics of GREP and manage to assemble this (1[3-9]|2[0-3]):[0-5][0-9]? for a Search change format and apply a copy of the paragraph format (with bolding added) to all the 12-23:59 times in the table.

 

From here I then did a number of search and replace scripts individuals for all the 13-23 and made their 12 hour equivalents. 1-11

 

Enter Scripting, I do know general javascript but I do not know the calls for InDesign or much of the syntax so there is a lot I do not know and generally I modify not design from new. I found the posts by @Kasyan_Servetsky in regards to findchangebylist.txt and began modifying everything into calls from my findchangebylist file.

 

And came up with this. (please ignore that the code box is for JS there's no option for plain text)

 

--FindChangeList.txt
--A support file for the InDesign AppleScript FindChangeByList.applescript
--
--This data file is tab-delimited, with carriage returns separating records.
--
--The format of each record in the file is:
--findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description
--
--Where:
--<tab> is a tab character
--findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).
--findProperties is a properties record (as text) of the find preferences.
--changeProperties is a properties record (as text) of the change preferences.
--findChangeOptions is a properties record (as text) of the find/change options.
--description is a description of the find/change operation
--
--Very simple example:
--text	{find what:"--"}	{change to:"^_"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all double dashes and replace with an em dash.
--
--More complex example:
--text	{find what:"^9^9.^9^9"}	{applied character style:"price"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find $10.00 to $99.99 and apply the character style "price".
--
--All InDesign search metacharacters are allowed in the "find what" and "change to" properties.
--

--Run 24 hour bolding first.
grep	{find what:"(1[2-9]|2[0-3]):[0-5][0-9]?"}	{applied character style:"ttc_passing_time BOLD"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find PM times and apply the character style "ttc_passing_time BOLD".

--Time change 24 hour clock to 12 hour clock

grep	{find what:"13:"}	{change to:"1:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 13:00 hour times replace with 1:00 times.
grep	{find what:"13:"}	{change to:"1:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 13:00 hour times replace with 1:00 times.
grep	{find what:"14:"}	{change to:"2:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 14:00 hour times replace with 2:00 times.
grep	{find what:"15:"}	{change to:"3:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 15:00 hour times replace with 3:00 times.
grep	{find what:"16:"}	{change to:"4:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 16:00 hour times replace with 4:00 times.
grep	{find what:"17:"}	{change to:"5:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 17:00 hour times replace with 5:00 times.
grep	{find what:"18:"}	{change to:"6:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 18:00 hour times replace with 6:00 times.
grep	{find what:"19:"}	{change to:"7:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 19:00 hour times replace with 7:00 times.
grep	{find what:"20:"}	{change to:"8:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 20:00 hour times replace with 8:00 times.
grep	{find what:"21:"}	{change to:"9:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 21:00 hour times replace with 9:00 times.
grep	{find what:"22:"}	{change to:"10:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 22:00 hour times replace with 10:00 times.
grep	{find what:"23:"}	{change to:"11:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 23:00 hour times replace with 11:00 times.
grep	{find what:"23:"}	{change to:"11:"}	{include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}	Find all 23:00 hour times replace with 11:00 times.

 

The issue I am running into is 1 although it bolds 12-23 it is not replacing the hours of 13:00 and 23:00 it is working for all the others so I have done something wrong but I do not know what.

 

The Ideal world would be an automated process where the XML is exporting from the Scheduling server ingested into an application (InDesign Server maybe?) and spits out preformatted printable and web friendly versions of the schedules but I haven't gotten to that point yet but that will be the next evolution of this, if you have any sugestions there I would be happy to hear them.

 

I am positive someone has done this and I am reinventing the wheel, does anyone see what I have done wrong or have an idea of a better solution script wise?

The project's files can be downloaded here.

 

As always thank you in advance.

Dustin

 

TOPICS
EPUB , How to , Import and export , Print

Views

915

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 , Apr 08, 2020 Apr 08, 2020

If you want to string together GREP searches without resorting to loading a complex text file, calling a grep function multiple times might be easier.

 

Something like this does the same without loading a text file, you would just need to string together the function calls:

 

//Applies the Character Style "Bold" to the search string without making a text change
grepSearch("(1[3-9]|2[0-3]):[0-5][0-9]?", NothingEnum.NOTHING, "Bold");

//Changes 13 to 1 without applying a character style
grepSearch
...

Votes

Translate

Translate
Community Expert ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

If you want to string together GREP searches without resorting to loading a complex text file, calling a grep function multiple times might be easier.

 

Something like this does the same without loading a text file, you would just need to string together the function calls:

 

//Applies the Character Style "Bold" to the search string without making a text change
grepSearch("(1[3-9]|2[0-3]):[0-5][0-9]?", NothingEnum.NOTHING, "Bold");

//Changes 13 to 1 without applying a character style
grepSearch("13", "1", NothingEnum.NOTHING);

//Changes 23 to 11 without applying a character style
grepSearch("23", "11", NothingEnum.NOTHING);

//Additional searches...


/**
* A grep find and change function   
* @param f the grep find string can be a grep string or nothing (NothingEnum.NOTHING)
* @param c the grep change string, use NothingEnum.NOTHING for no change
* @param s a character style to apply, use NothingEnum.NOTHING to skip 
*/	
function grepSearch(f,c,s){
    app.findGrepPreferences.findWhat=NothingEnum.NOTHING
    app.changeGrepPreferences.changeTo=NothingEnum.NOTHING
    app.findGrepPreferences.findWhat = f;
    app.changeGrepPreferences.changeTo = c;
    app.changeGrepPreferences.appliedCharacterStyle = s;
    app.activeDocument.changeGrep( true )
}

 

 

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 ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

Hello,

 

Thank you very much for the great concept. I realised I had to change the character style. Is there anywhere that these calls are documented?

 

The final script came out as

//Applies the Character Style "ttc_passing_time BOLD" to the search string without making a text change
grepSearch("(1[3-9]|2[0-3]):[0-5][0-9]?", NothingEnum.NOTHING, "ttc_passing_time BOLD");

//Changes 13 to 1 without applying a character style
grepSearch("13:", "1:", NothingEnum.NOTHING);
//Changes 14 to 2 without applying a character style
grepSearch("14:", "2:", NothingEnum.NOTHING);
//Changes 15 to 3 without applying a character style
grepSearch("15:", "3:", NothingEnum.NOTHING);
//Changes 16 to 4 without applying a character style
grepSearch("16:", "4:", NothingEnum.NOTHING);
//Changes 17 to 5 without applying a character style
grepSearch("17:", "5:", NothingEnum.NOTHING);
//Changes 18 to 6 without applying a character style
grepSearch("18:", "6:", NothingEnum.NOTHING);
//Changes 19 to 7 without applying a character style
grepSearch("19:", "7:", NothingEnum.NOTHING);
//Changes 20 to 8 without applying a character style
grepSearch("20:", "8:", NothingEnum.NOTHING);
//Changes 21 to 9 without applying a character style
grepSearch("21:", "9:", NothingEnum.NOTHING);
//Changes 22 to 10 without applying a character style
grepSearch("22:", "10:", NothingEnum.NOTHING);
//Changes 23 to 11 without applying a character style
grepSearch("23:", "11:", NothingEnum.NOTHING);

//Additional searches...


/**
* A grep find and change function   
* @param f the grep find string can be a grep string or nothing (NothingEnum.NOTHING)
* @param c the grep change string, use NothingEnum.NOTHING for no change
* @param s a character style to apply, use NothingEnum.NOTHING to skip 
*/	
function grepSearch(f,c,s){
    app.findGrepPreferences.findWhat=NothingEnum.NOTHING
    app.changeGrepPreferences.changeTo=NothingEnum.NOTHING
    app.findGrepPreferences.findWhat = f;
    app.changeGrepPreferences.changeTo = c;
    app.changeGrepPreferences.appliedCharacterStyle = s;
    app.activeDocument.changeGrep( true )
}

If I wanted to use the GREP search to change character styles at the same time would this be correct?

 

//Changes 16 to 4 without applying a character style
grepSearch("16:", "4:", "character style");

 

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 ,
Apr 09, 2020 Apr 09, 2020

Copy link to clipboard

Copied

If I wanted to use the GREP search to change character styles at the same time would this be correct?

 

//Changes 16 to 4 without applying a character style
grepSearch("16:", "4:", "character style");

 

Yes, the "character style" string needs to be changed to the exact name of a character style in the active document.

 

The current InDesign API is here

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ChangeGrepPreference.html

 

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 ,
Apr 09, 2020 Apr 09, 2020

Copy link to clipboard

Copied

Also, my script is changing the Character Style, so your "ttc_passing_time BOLD" would have to be a character style and not a paragraph style.

 

If you want to change Paragraph Styles change

app.changeGrepPreferences.appliedCharacterStyle = s;

to

app.changeGrepPreferences.appliedParagraphStyle = s;

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 ,
Apr 09, 2020 Apr 09, 2020

Copy link to clipboard

Copied

Wonderful thank you, yes "ttc_passing_time BOLD" is a Charicter style 🙂

 

This is exactly what I needed, and far simpler

 

That API link will be extreamly helpful.

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
Guru ,
Apr 10, 2020 Apr 10, 2020

Copy link to clipboard

Copied

Hi Dustin,

I suggest using another (simpler) approach:

 

main();

function main() {
	var doc = app.activeDocument;
	
	var foundItem, contents;
	app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
	app.findGrepPreferences.findWhat = "\\d{1,2}:\\d{2}";
	var foundItems = doc.findGrep();
	for (var i = 0; i < foundItems.length; i++) {
		foundItem = foundItems[i];
		contents = foundItem.contents;
		
		if (contents.match(/^\d{2}:/) == null) {
			contents = "0" + contents; // add leading zero if only one digit before colon
		}
	
		convertedTime = tConvert(contents);
		$.writeln(contents + " > " +convertedTime);
		foundItem.contents = convertedTime;
	}
}

function tConvert(time) {
  // Check correct time format and split into components
  time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];

  if (time.length > 1) { // If time format correct
    time = time.slice (1);  // Remove full string match value
    time[5] = +time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM
    time[0] = +time[0] % 12 || 12; // Adjust hours
  }
  return time.join (''); // return adjusted time or original string
}

 

2020-04-10_17-54-32.png

Hope it helps!

— Kas

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 ,
Apr 15, 2020 Apr 15, 2020

Copy link to clipboard

Copied

LATEST

Dustin, it looks like you've got a great start on this project, with great suggestions from Rob and Kasyan! Thought I'd let you know that I've scripted complete solutions for building transit schedules for the City of Minneapolis and King County (Seattle). The systems import XML data from their scheduling systems and build or update schedules in InDesign. If you should decide to contract for some help on this project, I'd be interested in talking with you. You can find me at gilbertconsulting.com.

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