Path separator problem . Finder / open panel

I`m trying to access access in finder

tell application “Finder”
if not (exists folder theLocation) then
set ds to “Error!”
set ds to “Done!”
end if
end tell

the path I got from “open panel”

set theLocation to item 1 of (path names of open panel as list)

The problem is that open panel returns path with “/” as folder separator, but finder uses “:”

How can I convert it? or make it work?

Thank You

I think you need to look into the “POSIX path” command. This is from the Standard Additions dictionary…

Also, try performing a search for POSIX in the AppleScript OS X forum, it should come up with a lot of examples to help you understand it.

Another good source to check would be our AppleScript FAQ section.

Thank you very much! Its so simple! I found the answer in FAQ link you posted!

I work a lot between the OS X command line and Finder and AS, so I’ve written functions to convert between Finder (“:” delimited) and UNIX (“/” delimited) paths. In addition these functions handle paths to non-startup drives, which via the command line must be accessed through /Volumes. Also, you can convert folder paths, not just file paths. Feel free to use it, copy it, and modify it. They’re not complicated, and actually use different methods. I take no responsibility for any harm that may come form using them.

on MactoUNIX(docFolder)
	set docFolderString to docFolder as string
	set docFolderString2 to "/"
	set startupDisk to ""
	tell application "Finder"
		set startupDisk to name of startup disk
	end tell
	set diskNameLength to length of startupDisk
	set tempStr to (characters 1 thru (diskNameLength + 1) of docFolderString) as string
	if tempStr contains startupDisk then
		set docFolderString2 to "/"
		set docFolderString2 to "/Volumes/"
	end if
	set counter to 1
	repeat while counter is less than ((length of docFolderString) + 1)
		set currChar to character counter of docFolderString
		if currChar is ":" then
			set docFolderString2 to docFolderString2 & "/"
			set docFolderString2 to docFolderString2 & currChar
		end if
		set counter to counter + 1
	end repeat
	return docFolderString2
end MactoUNIX

on UNIXtoMac(UNIXString)
	set temp1 to 0
	set macString to ""
	set UStart to (characters 1 thru 8 of UNIXString) as string
	if (UStart contains "Volumes") then
		set UNIXString to (characters 10 thru (length of UNIXString) of UNIXString) as string
		set UNIXString to characters 2 thru (length of UNIXString) as string
	end if
	repeat while (length of UNIXString) is greater than 0
		set temp1 to offset of "/" in UNIXString
		if temp1 is 1 then
			set macString to macString & ":"
			set macString to (macString & (characters 1 thru (temp1 - 1) of UNIXString) as string)
		end if
		if temp1 is not 0 then
			set macString to macString & ":"
			if temp1 is less than (length of UNIXString) then
				set UNIXString to (characters (temp1 + 1) thru length of UNIXString) as string
				set UNIXString to ""
			end if
			set UNIXString to ""
		end if
	end repeat
	return macString
end UNIXtoMac

Here’s an example that uses a couple of quick one-liners that are sometimes handy.

set colonPath to "folder 1:folder2:file"
set colon2slash to POSIX path of colonPath
display dialog "Before: " & colonPath & return & "After: " & colon2slash
set slash2colon to (POSIX file colon2slash) as text
display dialog "Before: " & colon2slash & return & "After: " & slash2colon

– Rob