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

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

Explorer ,
Mar 21, 2025 Mar 21, 2025

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!"

 

TOPICS
Scripting
82
Translate
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 21, 2025 Mar 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.

 

Translate
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 ,
Mar 24, 2025 Mar 24, 2025

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

Translate
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 21, 2025 Mar 21, 2025

@_Aaron_ 

 

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

 

Translate
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 ,
Mar 24, 2025 Mar 24, 2025
LATEST

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

Translate
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