Converting Paths

Hello!

I was wondering if there was a way to convert paths from this form:

My HD/Applications/iPhoto

to this form:

My HD:Applications:iPhoto

in OS X. (10.2.2 to be exact.)

Any help is appreciated!

There might be a better way to do this but this should work until someone provides it.

set slashPath to "My HD/Applications/iPhoto"
set colonPath to ""

repeat with i in slashPath
	if contents of i is "/" then
		set colonPath to colonPath & ":"
	else
		set colonPath to colonPath & i
	end if
end repeat

Thanks, it works perfect!

Yep. There is another way, but I couldn’t say whether or not it was “better”. :wink:

Text Item Delimiters to the rescue!

set slashPath to "My HD/Applications/iPhoto"

set AppleScript's text item delimiters to "/"
set theItems to every text item in slashPath
set AppleScript's text item delimiters to ":"

set colonPath to theItems as text
set AppleScript's text item delimiters to ""

how about this…works on my 10.2.2 system


set thePath to POSIX path of (choose folder)
set theOtherPath to (POSIX file thePath)

Brilliant!

Note to the original poster: If it’s just a string you need in the end, you’ll need to coerce the result.

set thePath to POSIX path of (choose folder)
set theOtherPath to (POSIX file thePath)
set theFinalText to (theOtherPath as text)

But there is also a small problem when you’re using Posix Path : you cannot use it on files or folder that have a space in their name (neither accuented characters I think…)
If i remeber well Billy Roger wrote a script to convert a Unix Stype Path to a Mac Style Path (but it(s not taking either accuented characters in count). Make a search in the scriptbuilders database with keyword ‘posix’ and you’ll find it it.

try it on a folder that contains a spaceor an accuentuated character and here is what you get :


set theAlias to alias "Utilisateurs:jeanbaptiste:Desktop:FB Osaxé:"
log the result

set posixPath to POSIX path of theAlias
log the result

set quotedPosixPath to quoted form of posixPath --(use quoted form in shell scripts) 
log the result

set fileSpec to posixPath as POSIX file
log the result

set theAlias to fileSpec as alias
log the result

Here is the result


(*alias Utilisateurs:jeanbaptiste:Desktop:FB Osaxé:*)
	(*/Volumes/Utilisateurs/jeanbaptiste/Desktop/FB Osaxé/*)
	(*'/Volumes/Utilisateurs/jeanbaptiste/Desktop/FB Osaxé/'*)
	(*file Utilisateurs:jeanbaptiste:Desktop:FB Osaxé:*)
	(*alias Utilisateurs:jeanbaptiste:Desktop:FB Osaxé:*)

I may be missing something :=))

The space in the name should be ‘escaped’ using a ‘’ no?

I can assure you that a path such the last one will not work when you use it in a shell script. If instead I use “/Volumes/Utilisateurs/jeanbaptiste/Desktop/FB\ osax” it will work as expected because I escaped the space and the ‘’.


set theAlias to alias "Macintosh HD:Users:has:føø bår.txt" 
set posixPath to POSIX path of theAlias 

do shell script "vi "& posixPath won't work, or whaterevr you do on your file. 

To see the ‘real’ POSIX path, simply drag an drop a file onto a terminal window

Ooops, sorry I just misread your answer, I’m sorry

Well, thanks again. I’ve tested your code now and it’s working perfectly (indeed should i say…). This was a major problem I was facing, so thanks again

Jean-Baptiste (who will expose all his problems now :=))

:?: :?: :?: :?: :?: :?:
Here have you found the ‘quoted from’. I have not been able to find it anywhere.
:?: :?: :?: :?: :?: :?:

it’s quoted form


set pathToAlias to (choose folder with prompt "Select the folder where the Files are located.") as alias
set quotedPOSIX to quoted form of POSIX path of pathToAlias

yeah, right, but it’s an error from my part, but it doesn’t tell me where it is , in which ditonary?

JB,

I don’t think it’s in a dictionary. If it is, I don’t where it is. I only found about it through the grapevine.

P.S. Did you get my email regarding the broken links on your web page?

Ohh! it should be in the Standard additions library but it is no!

bad bad bad dictionary people.