path conversion - file://localhost/.../test to Macintosh HD:...:test:

Hi everyone,

I guess its a lame question for most of you but I don’t get it.

I have a prompt to let the user coose a folder:

set source_folder to choose folder with prompt "select a folder:" as string

The result will look like this:
file://localhost/Users/myuser/Desktop

I need it to look like this:
Macintosh HD:Users:myuser:Desktop:

I have my workaround for converting which is finding parts of the first string and replacing them and repeating this until I get the path to look like I need it. This works but it’s quite some lines of code and I guess there is a smarter / nicer way of doing it.

Thanks in advance!

Cheers,
Chris

Hi,

just use parentheses


set source_folder to (choose folder with prompt "select a folder:") as string

Wow … so little difference in code :slight_smile: Thanks Stefan!

One more pathconversion that I do my crazy workaround for and there probably is a nicer way to:
I have a pathcontrol box and also need to convert it.

set thePath to pathControlBox's stringValue() as text

From the code above I again get:
file://localhost/…

but I need it to look like:
Macintosh HD:…:

The smartest way is a category to NSPathControl which supports HFS paths
as Shane describes in his book (chapter 16)

I keep forgetting looking into the book for specific questions… you are right, that is exactly what I need.
Thanks for pointing me to it!