How to simply change text color in Keynote


(Bodie Quirk) #1

Hello Script Debugger Community!

I just discovered Script Debugger from reading AppleScript 1-2-3! Oh my gosh, I can’t wait to learn this program. However, I have recently decided to dive into AppleScript because I use Keynote every day for work and I am getting tired of doing so many repetitive tasks. It’s time to automate!

I was wondering if you could help me get started with the most frustrating: font color changes! I am a WordPress developer trying to get a grasp of the basics of AppleScript, and I am used to hex codes not…whatever AppleScript uses to determine color codes.

Here is what I need help with: I need to create a script I can fire after I select some text that changes the color of the font to orange.

  1. The hex code for the color I need is #FF9300, but I don’t know how to write that same color in an AppleScript-friendly fashion
  2. I don’t know how to properly write the script in the first place. Do I need to set variables?

I have begun to take a crack at the script, but it doesn’t work (because I have no idea what I am doing) and I would love some help. Thanks so much!

property orangeText : {255, 147, 0}
tell application "Keynote" activate 
set the color of word of object text to orangeText 
end tell```

Excited to learn from this awesome community. Thanks for being kind to the newbies!

Bodie

(Shane Stanley) #2

Bodie,

Welcome. Hopefully someone who regularly scripts Keynote will come along shortly. I was going to point you to a useful Web site, but unfortunately it seems to be down at the moment.

Here are a couple of pointers:

  • Keynote has no accessible concept of the selection. Apart from using GUI scripting, that makes your request difficult to fill.

  • The RGB color values generally used by AppleScript range from 0 to 65535, which is 256 * 256 - 1.

  • You can’t use a class like word as the target of your command – you need to target a specific word. So something like this works:

tell application id "com.apple.iWork.Keynote" -- Keynote.app
	tell its document 1
		set color of word 1 of object text of text item 1 of current slide to {65535, 0, 65535}
	end tell
end tell

I hope that gets you started.


(Bodie Quirk) #3

Shane,

Thanks so much for the helpful reply. Definitely got me moving in the right direction, and taught me some valuable fundamentals too. Let me try this out! Appreciate your guidance.

Bodie


(Bodie Quirk) #4

Wait! What about applying paragraph styles? If I had the paragraph style all set up, is there a way to have AppleScript apply that style? That is actually what I really want to do. Man, if there was a way to just click a button and run a script that applies a style that would be awesome.


(Shane Stanley) #5

You’re out of luck, I’m afraid.


(Phil Stokes) #6

Don’t give up though. Tell Apple:

http://www.apple.com/feedback/keynote.html