Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm writing a series of lectures where I use a different font to indicate code. Is there any way to assign new shortcut keys/key combinations to select the two fonts I want?

share|improve this question
    
You should accept jm666's answer. It is excellent and I highly doubt you'll get a better one. –  CajunLuke Sep 15 '12 at 3:37
    
Also: if you use Eclipse as your IDE, it puts copied code onto the clipboard in rich text with the font you use in Eclipse and full syntax highlighting in addition to normal plain text. –  CajunLuke Sep 15 '12 at 3:39
    
@CajunLuke - it was a great answer, but it didn't work in practice. Another answer worked directly. Also, I have no idea what Eclipse is or why I'd be using it with Keynote. –  keflavich Sep 17 '12 at 0:03

3 Answers 3

up vote 3 down vote accepted

I didn't find any way to modify the style of the selection, but you could use UI scripting to select a font from the format bar.

tell application "System Events" to tell process "Keynote"
    tell pop up button 1 of window 1
        click
        click menu item "Menlo" of menu 1
    end tell
end tell

You could assign shortcuts to the scripts with FastScripts or by creating Automator services.

share|improve this answer
    
For me at least, it was pop up button 2 of window 1, but otherwise this works –  keflavich Sep 17 '12 at 0:01

I don't know any easy-simple way, but (as usual) Automator and scripting can provide some help.

The basic idea is:

  • You write the text with the Keynote's default font.
  • Select the text.
  • Press a hotkey - this will run the Automator script and replace the font for the selected text.

so, to make this work:

  1. Start Automator.
  2. Select the type "Service".
  3. At the top change "text" to "rich text" and set the checkbox "Output replaces…".
  4. From the Library in the left side drag into the right side the following actions. (You can use the search field to quickly locate the needed actions.)
    • "Copy to Clipboard"
    • "Run Shell Script" (and check the box "Ignore this action's input" in the action's Options)
    • "Get Contents of Clipboard"

into the "Run Shell Script" action enter:

pbpaste -Prefer rtf | textutil -stdin -convert rtf -font 'Menlo' -fontsize 32 -stdout | pbcopy

Replace the Menlo with your wanted font name and change the 32 to the needed size.

All the above is sounds complicated, but it is much faster to do it as reading the above. ;) Here's what your Automator screen should look like when you're done with the above steps:

image

Save and name the service, for example, as "SetMyFont". Now you have a new "Service", so let's check it out:

  • Start Keynote (or TextEdit or whatever program you'll want to use this Service in).
  • Select some text that you want to change the font of.
  • Go to menu: Keynote -> Services and select your previously named service, e.g. "SetMyFont".
  • Your selected text should now appear in the new font.

If the service works, you now should add a global hotkey for it:

  • Go to System Preferences -> Keyboard -> Keyboard Shortcuts.
  • In the "Services" tab, search for your service name, e.g. "SetMyFont". It should be in the "Text" group.
  • Select the checkbox and add a shortcut. (see screenshot)

enter image description here

  • And you're done!

A bit complicated to set up, but it works and when you have lots of text, it can speed up the formatting a bit.

(Somebody will likely suggest much simpler solution using AppleScript directly with Keynote.)

When you've finished the work and don't need the service anymore, you can remove the "SetMyFont.workflow" from the ~/Library/Services, or uncheck that checkbox in the Keyboard preference pane.

share|improve this answer
    
Why need to use the clipboard in the workflow and not uses stdin/stdout directly? –  cajwine Sep 7 '12 at 22:29
1  
Because for some (not very clear) apple's reason the "Shell script" action accepts (and produces) only "plain text" and not "rtf". Therefore need pass rtf to/from the shell-script via clipboard and pbcopy/pbpaste. –  jm666 Sep 7 '12 at 22:33
1  
I got it to work on 10.7, but it also changes the font color. Is there any way to preserve all OTHER text properties, and ONLY change the font? –  keflavich Sep 8 '12 at 18:41
1  
Unfortunately don't know any solution what preserving any formatting. What is possible to do, get the text and set some basic formatting properties - like, size, font-name. With a small modification is possible setup the color too, but you need to know the color RDB code or name. –  jm666 Sep 9 '12 at 17:03
1  
pbpaste and pbcopy don't preserve Unicode characters in Automator's default environment. You could fix that by adding export LC_CTYPE=UTF-8; to the start. (Terminal and iTerm set LC_CTYPE to UTF-8 by default.) –  Lri Sep 15 '12 at 5:01

Not by default, but according to Apple's Keynote shortcut page you can use:

Copy paragraph style Option-Command-C

Paste paragraph style Option-Command-V

Better than nothing, I hope.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.