« Theft and how I feel - Design Piracy Series | Main | Thank god I'm not alone »

June 10, 2008

TextMate to Keynote in 2 steps

Credit where credit is due: First, I have to give the credit for this to Allan Odgaard (of TextMate fame) and Ciaran Walsh. I just jumped into ##textmate and served as the catalyst by bringing up the topic and getting the ball rolling.

For my pastie presentation at RailsConf 2008 I showed a little code, but it was all screen snaps. I've since been told of this semi-annoying 4-5 step process to go from TextMate pretty code to a Keynote slide... but no more...

First, copy the "Create HTML From Document / Selection" command... yes, using the ++ command to copy... you can't just make a new command because evidentally you need some secret XML sauce that the original has and your copy will inherit... then change the command source to the following:

Update: You must put the duplicated command in the TextMate bundle, or this won’t work.


ruby -e'
require "jcode"
$KCODE="U"
require "#{ENV["TM_BUNDLE_SUPPORT"]}/lib/doctohtml.rb"
require "#{ENV["TM_SUPPORT_PATH"]}/lib/progress.rb"
unit = ENV.has_key?("TM_SELECTED_TEXT") ? "selection" : "document"
TextMate.call_with_progress(:message => "Creating HTML version of #{unit}…") do
  print document_to_html( STDIN.read, :include_css => true )
end'|textutil -convert rtf -stdin -stdout|pbcopy
echo 'Done!'

You can see we're just piping the output of TM's HTML generation into textutil to generate RTF. Then we're placing that on the clipboard. Here is what my dialog looks like:

Picture_3

You can assign the "Copy with Style" command to your own key binding... then it's as simple as copy/paste. Two keystrokes, done.

This seems to work great with Leopard, but still needs some testing on Tiger. It currently fails with an error about stdin. But hopefully this tip will help those of you preparing presentations with nicely colored Ruby code.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e552517e37883400e5534046998833

Listed below are links to weblogs that reference TextMate to Keynote in 2 steps:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

You must put the duplicated command in the TextMate bundle, or this won’t work.

I'm not sure, this is exactly, what you're looking for, but something like has already been done:
http://github.com/drnic/copy-as-rtf-tmbundle/tree/master

Nice approach though :)

Good old DrNic... guess I shouldn't be surprised he solved this already. :-) Looks like he actually wrote a Ruby RTF generator though, which is kind of cool and a totally different solution to the problem. Wonder if he just hadn't heard of textutil or if there is some hidden problem I haven't discovered yet.

This also works in PowerPoint if you go Edit > Paste Special as opposed to just paste (which means you can't Command+V)

I really need to buy iWork.

Yes, you do need to buy iWork.

@Josh: Unfortunately, I am simply an OS X pawn in a Windows environment. Unless they make an iWork player for Windows.

The comments to this entry are closed.

About the Author

Rails and Ruby Projects

Legal Stuff

  • The opinions I state here are my own and do not necessarily reflect the opinions of my clients, friends, lovers, employers, employees or anyone else.

    Copyright © 2008-2009 Josh Goebel. All rights reserved.