Help changing applescript to change font color in a text box

Explorer ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

I have this script working BUT I want to change the text INSIDE the text box to the "noprint" swatch

I am a beginner and have no clue.

 

Can someone help me?

 

tell application "Adobe InDesign 2022"

 

tell active document

delete unused swatches

set allSwatches to every swatch

make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}

make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}

set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}

set infoLayer to layer "Job Info - Non-Print"

 

end tell

 

 

 

 

tell the active document

 

tell the first spread

 

set slugText to make new text frame with properties ¬

{geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1}

set contents of slugText to "one" & return & "two"

 

 

end tell

 

end tell

 

end tell

TOPICS
Scripting

Views

309

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Jul 20, 2022 Jul 20, 2022

Here’s the entire script—didn’t need the extra skip colors array, just edit sl as needed, these are the colors that get skipped:

set sl to {"None", "Registration", "Paper", "Black"}

 

 

tell application id "com.adobe.indesign"
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end t
...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Hi @denisep726548,

Warning:- I am also a novice in AppleScripting, so try the following at your own risk 🙂

tell application "Adobe InDesign 2021"	
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		set infoLayer to layer "Job Info - Non-Print"
		
	end tell	
	tell the active document
		tell the first spread	
			set slugText to make new text frame with properties ¬
				{geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1}
			set contents of slugText to "one" & return & "two"
			tell parent story of slugText
				set fill color to "noprint"
			end tell	
		end tell
	end tell
end tell

-Manan

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Hi @denisep726548 , Also not sure if you would be running the script more than once, but if you try to make a swatch or layer that already exists you’ll get an error. You can wrap the make color or make layer lines in a try statement like this:

 

 

tell application id "com.adobe.indesign"
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		try
			wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		on error
			set wb to every color whose name is "wb"
		end try
		try
			set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		on error
			set infoLayer to every layer whose name is "Job Info - Non-Print"
		end try
		tell spread 1
			set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1}
			set contents of slugText to "one" & return & "two"
			set fill color of text 1 of slugText to "noprint"
		end tell
	end tell
end tell

 

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Both of you are awesome! Thank you so much. That works for me.

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

So if I take it one more step, how would I get this to add text to the same box, listing all swatches that are actually used on the page?

For example:

Swatches Used: noprint, black, Pantone 123

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

I think you would have to loop thru the spread’s page items and check the fills and strokes. Something like this:

 

 

 

tell application id "com.adobe.indesign"
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		try
			wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		on error
			set wb to every color whose name is "wb"
		end try
		try
			set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		on error
			set infoLayer to every layer whose name is "Job Info - Non-Print"
		end try
		tell spread 1
			
			---------gets the spread’s used swatches---------
			
			--the spread’s page items
			set api to all page items
			--an array to check used swatches
			set sl to {}
			--a string for the used names
			set ul to "Used Swatches:" & return
			
			--loop thru the page items and get their fills and strokes
			repeat with x in api
				set fn to name of fill color of x
				
				--check if the color is in the array 
				--and if not add it to the array and to the string list
				if fn is not in sl then
					copy name of fill color of x to beginning of sl
					set ul to ul & name of fill color of x & return
				end if
				
				--same for strokes
				set sn to name of stroke color of x
				if sn is not in sl then
					copy name of stroke color of x to beginning of sl
					set ul to ul & name of stroke color of x & return
				end if
			end repeat
			
			------------------------------------------
			
			set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1}
			--se the contents to the list
			set contents of slugText to ul
			set fill color of text 1 of slugText to "noprint"
		end tell
	end tell
end tell

 

Screen Shot 52.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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Excellent. Is there a way to exclude certain swatches like None??

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Yes make an array of names to skip. The repeat loop would look like this where ds is the array of names to skip:

 

			---------gets the spread’s used swatches---------
			
			--the spread’s page items
			set api to all page items
			--an array to check used swatches
			set sl to {}
			set ds to {"None", "Registration", "Paper", "Black"}
			--a string for the used names
			set ul to "Used Swatches:" & return
			
			--loop thru the page items and get their fills and strokes
			repeat with x in api
				set fn to name of fill color of x
				if fn is not in sl and fn is not in ds then
					copy name of fill color of x to beginning of sl
					set ul to ul & name of fill color of x & return
				end if
				set sn to name of stroke color of x
				if sn is not in sl and sn is not in ds then
					copy name of stroke color of x to beginning of sl
					set ul to ul & name of stroke color of x & return
				end if
			end repeat
			
			------------------------------------------

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Also, a new info text frame is created everytime the script runs, so you might want to clear your info layer at the beginning

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

tell spread 1
   delete every page item of item 1 of infoLayer

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Where do I insert this?

I cant figure it out. (I know.....I have no clue )

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Here’s the entire script—didn’t need the extra skip colors array, just edit sl as needed, these are the colors that get skipped:

set sl to {"None", "Registration", "Paper", "Black"}

 

 

tell application id "com.adobe.indesign"
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		try
			wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		on error
			set wb to every color whose name is "wb"
		end try
		try
			set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		on error
			set infoLayer to every layer whose name is "Job Info - Non-Print"
		end try
		--delete all page items of infoLayer
		
		tell spread 1
			delete every page item of item 1 of infoLayer
			
			---------gets the spread’s used swatches---------
			
			--the spread’s page items
			set api to all page items
			--an array to check used swatches, these are skipped
			set sl to {"None", "Registration", "Paper", "Black"}
			--a string for the used names
			set ul to "Used Swatches:" & return
			
			--loop thru the page items and get their fills and strokes
			repeat with x in api
				set fn to name of fill color of x
				if fn is not in sl then
					copy name of fill color of x to beginning of sl
					set ul to ul & name of fill color of x & return
				end if
				set sn to name of stroke color of x
				if sn is not in sl then
					copy name of stroke color of x to beginning of sl
					set ul to ul & name of stroke color of x & return
				end if
			end repeat
			
			------------------------------------------
			
			set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1, item layer:"Job Info - Non-Print"}
			--se the contents to the list
			set contents of slugText to ul
			set fill color of text 1 of slugText to "noprint"
		end tell
	end tell
end tell

 

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Thank you again!!!!!

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Hi @denisep726548 , If you are trying to learn scripting you might consider starting with JavaScript rather than AppleScript—mostly because you’ll find more expert JavaScripters on the forum when you have questions.

 

On the surface AppleScript’s language seems friendlier and easier to use, but in the end JS isn’t any harder just different syntax. It is easier to move between applications with AppleScript, so that might be a consideration if the usage will always be on MacOS.

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Dang. When I try to use it on a file with more content in it, I get this error. Do you know what that means?

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

There’s probably a group on the page. Try this

 

tell application id "com.adobe.indesign"
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		try
			wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		on error
			set wb to every color whose name is "wb"
		end try
		try
			set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		on error
			set infoLayer to every layer whose name is "Job Info - Non-Print"
		end try
		--delete all page items of infoLayer
		
		tell spread 1
			delete every page item of item 1 of infoLayer
			
			---------gets the spread’s used swatches---------
			
			--the spread’s page items
			set api to all page items
			--an array to check used swatches, these are skipped
			set sl to {"None", "Registration", "Paper", "Black"}
			--a string for the used names
			set ul to "Used Swatches:" & return
			
			--loop thru the page items and get their fills and strokes
			repeat with x in api
				try
					set fn to name of fill color of x
					if fn is not in sl then
						copy name of fill color of x to beginning of sl
						set ul to ul & name of fill color of x & return
					end if
					set sn to name of stroke color of x
					if sn is not in sl then
						copy name of stroke color of x to beginning of sl
						set ul to ul & name of stroke color of x & return
					end if
				end try
			end repeat
			
			------------------------------------------
			
			set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1, item layer:"Job Info - Non-Print"}
			--se the contents to the list
			set contents of slugText to ul
			set fill color of text 1 of slugText to "noprint"
		end tell
	end tell
end tell

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

This is good. I also am wondering how I would have it recognize swatches used in placed files. right now it does not see colors in an illustrator eps I have placed.

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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Unless the colors in the eps are defined as Spot they don’t get added to the InDesign Swatches panel, so you are probably out of luck there.

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Oh! You are correct. It is cmyk. Sorry about that.

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
community guidelines
Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Oh boy. Sorry. It ONLY reports wb and noprint in the swatches used, even if other spot colors are in the list. Can you still help me? I appreciate 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
community guidelines
Adobe Community Professional ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Not seeing a problem

 

Before (Gray50 and Gray20 are unused swatches, which your code deletes at the beginning):

Screen Shot 2.png

 

After

Screen Shot 3.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
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

I will attach a file with a placed eps in it. I need it to recognize colors used in the eps as well.

Right now it only lists color used that are built in indesign for some reason. Not what is used in the eps.

 

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
community guidelines
Adobe Community Professional ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

The script is only getting page item fills and strokes not text.

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
community guidelines
Explorer ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

I would need text and any placed content to be reported.

I know this is getting to be a lot to ask, but I really appreciate 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
community guidelines
Adobe Community Professional ,
Jul 21, 2022 Jul 21, 2022

Copy link to clipboard

Copied

We can add text checking, but you can’t look into the .eps without opening it in Illustrator and running an additional repeat loop there—doable but considerably more complex.

 

Also, a color could be used on the spread but not print, i.g. a fill with a 0% tint or a fill in an object that is hidden or behind another page item.

 

The spot color in the eps is available in the swatches panel because it has been brought in with the EPS, but there would be no way for sure to check if the color is actually being used on the first spread. The EPS’s process colors are not available from InDesign.

 

This version also checks the fills and strokes of InDesign text characters—it wouldn’t get text in tables:

 

 

tell application id "com.adobe.indesign"
	tell active document
		delete unused swatches
		set allSwatches to every swatch
		try
			set noprint to make color with properties {model:spot, space:CMYK, color value:{100, 0, 0, 0}, name:"noprint"}
		on error
			set noprint to every color whose name is "noprint"
		end try
		try
			wb to make color with properties {model:spot, space:CMYK, color value:{0, 0, 0, 100}, name:"wb"}
		on error
			set wb to every color whose name is "wb"
		end try
		try
			set infoLayer to make layer with properties {name:"Job Info - Non-Print", printable:true, layer color:blue}
		on error
			set infoLayer to every layer whose name is "Job Info - Non-Print"
		end try
		
		tell spread 1
			--removes existing info
			delete every page item of item 1 of infoLayer
			
			---------gets the spread’s used swatches---------
			--the spread’s page items
			set api to all page items
			--an array to check used swatches, these are skipped
			set sl to {"None", "Registration", "Paper", "Black"}
			--a string for the used names
			set ul to "Used Swatches:" & return
			
			--loop thru the page items and get their fills and strokes
			repeat with x in api
				--checks the page item and appends the used color list via the getColor handler
				set ul to ul & my getColor(x, sl)
				--if the page item is a text frame check each character
				if class of x is text frame then
					set txt to object reference of every character of x
					repeat with c in txt
						set ul to ul & my getColor(c, sl)
					end repeat
				end if
			end repeat
			
			set slugText to make new text frame with properties {geometric bounds:{(item 4 of page 1's bounds), 0.25, ((item 3 of page 1's bounds) + -1), 3}, stroke color:"noprint", stroke weight:1, item layer:"Job Info - Non-Print"}
			--set the contents to the list
			set contents of slugText to ul
			set fill color of text 1 of slugText to "noprint"
		end tell
	end tell
end tell


--Gets the fill and stroke color of an object and returns the color name 
--param the object to check 
--param the array of colors 
--returns a string with the color name 

on getColor(o, a)
	tell application "Adobe InDesign 2021"
		set s to ""
		try
			set fn to name of fill color of o
			if fn is not in a then
				copy name of fill color of o to beginning of a
				set s to s & name of fill color of o & return
			end if
			set sn to name of stroke color of o
			if sn is not in a then
				copy name of stroke color of o to beginning of a
				set s to s & name of stroke color of o & return
			end if
		end try
	end tell
	return s
end getColor

 

 

 

 

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
community guidelines