Keynote -- Determine color of Presenter Notes to color a cell in Excel

Hi there,

I’m trying to write script to determine the color or Paragraph Style of Keynote’s Presenter Notes in order to color fill a cell in Excel.

This is just a test script, so it only references one slide. Eventually I’ll turn it into a procedural script to do it for the whole deck. I’m not using the entire Presenter Note, only the first paragraph. Each slide’s notes will be a specific color and Paragraph Style, so I’m fine with referencing either.

So what I’m trying to do here is determine the color/style of the first paragraph of the presenter notes of slide 3. Then, I’ll reference the result to fill a cell in the matching row (equal to slide #) with the same color. For this example, I’m using white, but the final product will cycle through four colors.

When I run the code, I get this error, where “ID #2” is the first paragraph of the presenter note:

"

Does anyone here know how to reference the color and/or paragraph style of Keynote’s Presenter Notes?

tell application "Keynote"
	tell front document
		tell presenter notes of slide 3
			set idQuery to paragraph 1
			if name of paragraph style of idQuery is "ID#" then --Also happy to reference a color here
				set idColor to "{255, 255, 255}"
				tell application "Microsoft Excel"
					tell active sheet
						tell column "B"
							tell row 3
								tell interior object of cell 2
									set color to {255, 255, 255}
								end tell
							end tell
						end tell
					end tell
				end tell
			end if
		end tell
	end tell
end tell[/AppleScript]

Thanks in advance for any advice you can provide!

Update: Obviously, I was wrong about what you can or can’t work with. Dunno why but I was getting errors when I attempted this yesterday.

You can work with the properties of paragraphs (as well as words and characters). These include font, font-size, font-colour. Note that colour in iwork apps (and applescript) is described with 16-bits whereas in excel it’s with 8-bits so you’ll need to convert, and ideally control the iwork colour if consistency between apps is important. I find that a factor of 257 works well for me (but I haven’t tested that for consistency). That said, applescript will actually work (I think) with the first character of whatever object you reference rather than the entire object, as you may have multiple colours within a word or paragraph, so I’ve set that explicitly.

tell application "Keynote"
	tell front document
		tell presenter notes of slide 3
			set colour_of_crap to color of first character
			--> {3407, 24786, 410}
		end tell
	end tell
end tell

set exCol to {}
repeat with x from 1 to 3
		set end of exCol to (item x of colour_of_crap) / 257 round
end repeat
	--> {13, 96, 2}

tell application "Microsoft Excel"
	tell active sheet
		set color of interior object of range "B3" to exCol
	end tell
end tell

FYI the ’

' tag here is case sensitive. It's easiest to just select the code and click the button.

Hi there. Yes, does.

The following example does not claim to be complete, but answers the last question posed. I recommend running it in the Script Debugger to analyze the structure of presentation notes better.

Also, I want to note that the “style” property does not exist in KeyNote paragraphs, so we create the style ourselves (as in the example) and then set the if condition on it.


tell application "Keynote" to tell front document to tell slide 3
	tell presenter notes
		set PNobject to a reference to it -- a reference to presenter notes object
		tell its paragraph 1 -- a reference to its paragraph 1
			set {R, G, B} to its color
			set theStyle to {its color, its font, its size}
		end tell
	end tell
end tell

-- if theStyle is {{255,255,255},"HelveticaNeue",22} then then
-- tell application "Microsoft Excel" to tell active sheet
-- set color of interior object of range "B3" to {round (R/257), round (G/257), round (B/257)}
-- end tell
-- end if

Thanks, Mockman! That worked perfectly for me. Much appreciated!

KniazidisR, that script didn’t quite work for me, but thank you for your help!

It is unclear how @Mockman’s erroneous code works by paragraph colours, denying their existence. And without containing if condition. And my code, which works for me according to the colours of paragraphs, does not work for you in any way.

The fact that you could not put down the style you need in the if condition does not mean that it does not work. This is to inform other users that your last post will be misleading.

You’re welcome. Glad it works for you.