- 2008-07-11
So here’s a very small target market: people who use a Mac and use Keynote presentation software and also need to open files in a text editor called TextMate from their presentation and are comfortable running Ruby scripts on the command line: in other words, just about every Rails developer I know.
I’m giving a tutorial presentation this summer on Rails plugins and I wanted to be able to make links in my presentation using the TextMate URL scheme to open up plugin files in TextMate. Keynote, however, tries to be very helpful and silently removes the link you’ve just typed if it doesn’t start with http or https.
What I need is a proxy, so I wrote one using Sinatra. That TextMate URL scheme is ugly as sin anyway, so this is useful even if you aren’t in my unique situation. Here’s the script:
require 'rubygems' require 'sinatra' get '/*' do file, line = request.path_info.split(/:/) local_file = File.join(Dir.pwd, file) if (File.exists?(local_file)) redirect "txmt://open/?url=file://#{local_file}&line=#{line}" else not_found end end
Save this as webmate somewhere accessible. If you run webmate while in a directory, it will give you access via HTTP to opening files in that directory. Here’s an example script:
baltika:~ cnixon$ cd Projects/crnixon.org/ baltika:crnixon.org cnixon$ webmate == Sinatra has taken the stage on port 4567 for development # Go to the URL http://localhost:4567/content/index.txt:10 127.0.0.1 - - [10/Jul/2008 23:11:38] "GET /content/index.txt:10 HTTP/1.1" 302 - 0.0034
And TextMate opens ~/Projects/crnixon.org/content/index.txt and moves the cursor to line 10.
View the forum thread.