Keynote: change text to black

Hi, all.

I have an AS that looks at an open Keynote file
gets the image(s) names on a slide
makes a text box below the image(s) with the images name(s)
Loops through the rest of the slides and does the same.

This has worked great for dozens of Keynote file.

But, I got a file from a user that when I run the AS on it, it makes the type in the boxes white. I’m trying troubleshoot why her files are doing this but also wanted to see if I can just make sure that the AS can force all the type in the boxes to be black. I’ve tried a couple of things but can seem to get it to work. I’ve copied some stuff from Sal S. but still can’t get it working. Attached is the current code with some stuff from Sal that noted.

set correctColor to "0,0,0"


tell application "Keynote"
	activate
	
	try
		
		set slideCondition to false
		set slideNumber to 1
		set thisSlide to slide slideNumber of document 1
		set docCondition to false
		
		repeat until docCondition is true
			
			repeat until slideCondition is true
				
				if the number of images in thisSlide is 0 then
					set slideNumber to (slideNumber + 1)
					set thisSlide to slide slideNumber of document 1
				else
					set slideCondition to true
					
				end if
			end repeat
			
			set imageNumber to 1
			set imageName to (file name of image imageNumber of thisSlide)
			set imagesDone to false
			
			repeat until imagesDone is true
				try
					get position of (image imageNumber of thisSlide)
					copy the position of image imageNumber to {imageOneHorizVal, imageOneVertVal}
				end try
				
				set thisDocument to document 1
				set imageOne to (image imageNumber of current slide of document 1)
				tell thisDocument
					
					
					tell the current slide
						-- Make simple text item
						set thisTextItem to ¬
							make new text item with properties {object text:imageName}
						tell thisTextItem
							set the size of its object text to 20
							set the font of its object text to "Avenir Next LT Pro"
							
-- this repeat is Sal's 
repeat with i from 1 to the length of thisDisplayText
								set thisRGBColorValue to my generateRandomRGBColorValue()
								set the color of character i of object text to thisRGBColorValue
							end repeat
							
							set the position of thisTextItem to (position of imageOne)
							copy the position of thisTextItem to {thisHorizontalValue, thisVerticalValue}
							set imageOneHeight to height of imageOne
							set the position of thisTextItem to {thisHorizontalValue, (thisVerticalValue + imageOneHeight)}
							
							if the number of images in thisSlide is greater than imageNumber then
								set imageNumber to imageNumber + 1
								set imageName to (file name of image imageNumber of thisSlide)
							else
								set imagesDone to true
							end if
							
						end tell
					end tell
				end tell
			end repeat
			
			set slideNumber to slideNumber + 1
			set thisSlide to slide slideNumber of document 1
			
		end repeat
	end try
end tell

--this is Sal's
on generateRandomRGBColorValue()
	set RedValue to 0
	set GreenValue to 0
	set BlueValue to 0
	return {RedValue, GreenValue, BlueValue}
end generateRandomRGBColorValue 

Model: iMac Pro (2017)
AppleScript: latest
Operating System: macOS 10.14

Here is just a draft code showing how to set the color of a text item.

tell application "Keynote" to tell document 1
	tell current slide
		tell text item 1
			set its object text to "blah blah"
			tell its object text
				set its color to {0, 0, 0} -- Black
			end tell
		end tell
	end tell
end tell

In your original script the variable thisDisplayText is used but is never defined.
I guess that there is a typo and that thisDisplayText must be replaced by thisTextItem.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 27 novembre 2019 21:08:22

EXCELLENT! Thanks, Yvan :slight_smile: