Handling txmt:// URLs in... Windows!
So, let’s say you are like me and you have both a Mac and a Windows computer living side by side, presumably for cross-platform testing. Let us further assume your preferred editor of choice is TextMate (as it damn diddly well should be!) and you installed the supremely useful TextMate Footnotes Plugin for your Rails app.
It should then be quite reasonable to also assume that you are usually running your browser in Windows (especially if you give each computer a monitor and move between them with Synergy) Unfortunately, looking at your app from Windows also makes TextMate Footnotes supremely useless since all those nifty txmt:// links lead to no-where in particular.
No more!
With a little help from DRB, it is really quite easy to get your Windows computer to open TextMate over the network.
The
gist of it is that you’re going run a DRb server on your Mac, which can
be called by a ruby script running on Windows, which in turn is
registered to be the handler for the txmt:// ‘protocol’.
The server script
# txmt-server.rb
PORT = 7777
require 'drb'
require 'uri'
require 'cgi'
class MateServer
def open(url)
params = CGI::parse(URI::parse( url).query)
`mate -l #{params["line"][0].to_i} "#{params["url"][0][7..-1]}"`
end
end
DRb.start_service("druby://:#{PORT}", MateServer.new)
puts "Started MateServer on port #{PORT}..."
DRb.thread.joinThis is the one that runs on your Mac. Change PORT if you’d like.
The client script
# txmt-client.rb
DRB_SERVER = 'druby://!SERVER-IP!:7777'
require 'drb'
DRb.start_service
ms = DRbObject.new(nil, DRB_SERVER)
ms.open(ARGV[0])This one will be ran on windows. Set to the IP to wherever txmt-server.rb is running and save it somewhere.
Registering the txmt:// protocol with Windows
Intuitively, this is done via the registry (duh…). Create a .reg file and put this in it:
REGEDIT4
[HKEY_CLASSES_ROOT\txmt]
@="URL:txmt Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\txmt\shell]
[HKEY_CLASSES_ROOT\txmt\shell\open]
[HKEY_CLASSES_ROOT\txmt\shell\open\command]
@="\"C:\\rubyw.exe\" \"C:\\txmt-client.rb\" \"%1\""
Replace C:\\rubyw.exe and C:\\txmt.rb with your actual paths, doubling-up all back-slashes.
Double click the .reg file to have it added to your registry.
That’s it!
Provided the server is running on your mac and your network is up clicking on txmt:// links in Windows will work just like it did on your Mac. Hooray!
Danger Will Robinson!!!
I made this script for my own home use, which happens to sit comfortably behind a router/firewall. It is a security hole since somebody can call the open method with something that ends up getting executed in your shell.
DO NOT USE THIS ON A PUBLIC NETWORK!
SERIOUSLY!
With that in mind, I hope at least a single person finds this useful. Stranger things have happened.
- read more
- 01 Apr 2007 02:21
- no comments
Older posts: 1 2
Copyright © Intractable Complexity
Powered by Typo