Using TextMate from Windows

Remotely call TextMate from within Windows and have it pop up in macOS!

— Binary Adventures

TextMate needs little to no introduction for macOS users. It’s one of the platform’s most popular text editors and my personal weapon of choice, except when editing extremely large text files, which is TextMate’s Achilles’ heel.

As I’m anything but a fan of Windows and simultaneously forced to work with the OS professionally, I try to make the experience as painless as possible. Sure, Windows has its number of perfectly adequate text editors (Notepad++ comes to mind), but text editors are a strange beast and once you have found your match, it’s difficult to stray.

Anyway, this post will not show you how to run TextMate within Windows (it would probably be a suboptimal), but rather how to call TextMate from within Windows. Specifically, from within a Windows virtual machine (though it will work on a regular machine as well, it’ll just be more cumbersome).

Somewhere in the past, TextMate introduced rmate which allows you to call TextMate remotely and pass the file you’d like to edit.

In the past, TextMate has suffered with editing files on a server, but that’s all changed now. If you regularly find yourself SSHed into a remote box and wanting to edit a file using TextMate on your own box, your ship has come in.

TextMate 2 now ships with an rmate (Ruby) script that you can drop onto servers. When you trigger rmate on a remote box, it will connect back to your box, allow you to edit, and update the file on the server with the changes.

While rmate’s main purpose is to be used in combination with SSH connections, this is not a requirement. The same goes for the Ruby version: I’m not familiar with Ruby and prefer to use Python. Luckily, someone has made the effort to create a Python port of the script, which is what I use. For the sake of simplicity, I’m going to assume you have a working Python3 environment on your Windows host.

However, neither the Ruby nor the Python script will run within a Windows environment, as both depend on fork, which is something Windows doesn’t implement. How do we solve this? Simple: just remove the call. The consequence is limited: the calling process will “hang” while you edit the file, up until you close TextMate and it can resume.

Go ahead and clone (or download) the rmate-python repository. Then head to the bin folder and edit the rmate script. These are the two lines you need to remove to make the script work on Windows (line 297 - 298):

if not settings.wait and os.fork():

Next, I created a batch file to call rmate with a predefined host IP address, which is the macOS host that is running the Windows VM (the VMware network is set to NAT). This is what the batch file looks like (C:\Dev\repos\rmate-python is where I cloned the git repo):

@echo off
python C:\Dev\repos\rmate-python\bin\rmate --host %1

Add the batch file’s location to your PATH environment variable (so you can call it from anywhere you want). Another option is the less known doskey feature and use the Windows Command Processor to make the setting persistent (hat tip to this StackOverflow answer).


@doskey rmate=C:\Dev\repos\rmate-python\bin\rmate --host $*

Save this to a file (e.g. env.cmd) and then edit the Registry to call that file every time you open a new command window, effectively making the doskey setting persistent.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]

Result: you can now type rmate whateveryourfileiscalled.txt and TextMate will open the file in your macOS host. Make the necessary changes, save and close TextMate.