Skip to main content
denisep726548
Inspiring
July 19, 2022
Answered

Help changing applescript to change font color in a text box

  • July 19, 2022
  • 2 replies
  • 3858 views

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

This topic has been closed for replies.
Correct answer rob day

Where do I insert this?

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


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

 

2 replies

rob day
Adobe Expert
July 20, 2022

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

 

denisep726548
Inspiring
July 20, 2022

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

rob day
rob dayCorrect answer
Adobe Expert
July 20, 2022

Where do I insert this?

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


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

 

Adobe Expert
July 20, 2022

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