Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom Service that I've created in Automater (I'm on OSX 10.6.5). The Service executes an AppleScript which in turn executes a shell script. Here is the AppleScript:

on run {input, parameters}
    -- do shell script "/usr/bin/find " & input & " -type f -name .DS_Store -delete -print"
    display alert "Path: " & input
end run

The problem is, the path passed by the Service (in the variable input) looks like:

Macintosh HD:Users:Matthew:Documents:Programming:Apple Scripts:

And for the command to execute properly, the path needs to look like:

Macintosh\ HD/Users/Matthew/Documents/Programming/Apple\ Scripts/

So, is there a way to translate the first path to the second path? I was hoping for a core function which handles this. But I suppose some kind of regex/find/replace/etc would work? I'm familiar with HTML/CSS/Javascript/PHP, not with Cocoa/AppleScript/C. Any direction or suggestions would be great!

share|improve this question
I have always wondered about that. Thanks for asking! – daviesgeek Sep 20 '11 at 4:14

Use quoted form of the POSIX path of input. Without the quoted form of part, it won't handle funny characters (like spaces) in filenames correctly. See this Apple technote.

share|improve this answer
Yes...I found that out the hard way. Good info! – matthewpavkov Dec 14 '10 at 6:13
up vote 6 down vote accepted

Ok...this was easier than I had realized. After some Googling, it looks like what I need here is the POSIX path of command. This converts a given path to a Unix style path, which is the type of path you would see/use in Terminal. So:

POSIX path of input

Gives me a path like:

/Users/Matthew/Documents/Programming/Apple Scripts/

It seems to take into account that you just need a / at the beginning of the path, rather than the hard drive name. It does not, however, escape \ spaces (or handle special characters) in the path. So, as the other answer here mentions, you need to place the path in quotes ( " or ' ) in order for those spaces (or special characters) to be interpreted literally. You accomplish this by using quoted form of. Here it is:

quoted form of the POSIX path of the input
-- gives a path like: '/Users/Matthew/Documents/Programming/Apple Scripts/'
share|improve this answer
The / at the beginning of the path is the boot volume. Other hard drives are under /Volumes/ – Josh Dec 14 '10 at 17:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.