Saturday, April 25, 2009

Converting Windows paths to Mac paths and vice versa [updated]

In many companies there are network file servers which are mapped to drive letters in windows, for instance "K:" and to a volume name in Mac OS X, for instance "Clients". People working on either platform need to share content, and thus send links to folders on the server. But the urls on the mac and in windows doesn't match.

I have created a small Mac application that solves this issue. It's a simple Applescript application and the source is editable.

Simply drag the application bundle to your /Applications folder and drag it onto the dock to create a shortcut.

Open the application in the Applescript editor and change the following two lines to the values of your network drive:

set windowsDriveLetter to "K:"

set macVolumeName to "Clients"

It has two modes, Windows path to Mac path, and Mac path to windows path.
  1. Click in the icon to start the application. A dialog appears, where you can enter a windows path. When clicking "Ok", a new finder window pops up with the entered folder.
  2. Drag a folder onto the dock icon. A dialog appears where the corresponding windows path is selected and ready to copy paste.
Download it here

I really should create a nice icon for it...

[update on 21 aug 2009]
Spaces in windows path are now correctly escaped with "\ " in the corresponding mac path.

[update on 3 sep 2009]
A convenient way of doing this, as pointed out by Gerhard Schoenthal, is to create an Automator Service action which copies the path to the clipboard, especially since the Service menu became contextual in Snow Leopard. I have basically just modified the approach found here, and added the windows path conversion.

Following the steps below will create a new menu item under "Services", which will be visible when a file or folder is selected in the finder.

Download this file, and copy it to Library/Services under you user home folder.

Or you can create the service in Automator, and add the following Applescript Snippet:

on run {input, parameters}

-- SETTING: Change the windows drive letter here
set windowsDriveLetter to "K:"

tell application "Finder"
set itemPath to selection as string
set my text item delimiters to ":"
-- Skip /Volumes and DriveName, i.e. start from 2
set filePath to text items 2 through -1 of itemPath
set winPath to {windowsDriveLetter} & filePath
set my text item delimiters to "\\"
set finalPath to (winPath as text)
set the clipboard to finalPath
end tell

return input
end run