Skip to main content
_Aaron_9278756
Known Participant
March 21, 2025
Question

Here's an Applescript for tables, adds hyphen to every blank white cell

  • March 21, 2025
  • 2 replies
  • 217 views

With thanks to our AI cohabitants. You need to have predefined a swatch in your doc called "BlankCell"; mine is simply a light yellow tint.

 

 

-- For every blank (and unfilled with swatch) cell in every table, replace contents with "<><>" and color it with swatch "BlankCell"
-- 3/25, thanks to chatGPT

tell application "Adobe InDesign 2025"
	tell active document
		--	set theBlankStyle to cell style "BlankCell"
		set blankSwatch to swatch "BlankCell"
		repeat with s from 1 to count of stories
			tell story s
				repeat with t from 1 to count of tables
					tell table t
						repeat with r from 1 to count of rows
							tell row r
								repeat with c from 1 to count of cells
									tell cell c
										--set cellContent to contents
										if contents is "" and name of fill color is "None" then
											--beep
											set contents to "–"
											--set applied cell style to theBlankStyle 
											set fill color to blankSwatch
											
										end if
									end tell
								end repeat
							end tell
						end repeat
					end tell
				end repeat
			end tell
		end repeat
		
	end tell
end tell

say "All done!"

 

2 replies

Robert at ID-Tasker
Legend
March 21, 2025

@_Aaron_9278756 

 

Are you aware, that your code will mark as "empty" - overset cells?

 

But if that's the purpose of your code - you should be chekcing "overflows" property: 

 

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

 

That's why I'm checking myCells[a].texts[0].contents - not myCells[a].contents

 

_Aaron_9278756
Known Participant
March 24, 2025

@Robert at ID-Tasker, thank you for flagging that! Definitely not what I intended. When I have time I'll amend the code.

Robert at ID-Tasker
Legend
March 21, 2025

Just in case - JS version so will work on a PC as well - no AI involved 😉

 

var myCells = app.activeDocument.stories.everyItem().tables.everyItem().cells.everyItem().getElements();
for ( var a = 0; a < myCells.length; a++ ) 
{
   if (myCells[a].texts[0].contents == '')
   {
     myCells[a].fillColor = 'RED';
   };
};

 

Swatch / Color "RED" needs to be defined.

 

_Aaron_9278756
Known Participant
March 24, 2025

Cool, Robert! Yeah JS makes much more sense for cross-compatibility; I bias toward AS only because it's less cryptic.