Wednesday, July 18, 2018

#1 2002-12-08 11:56:49 am

JBadger
Member
From:: Calgary, Alberta
Registered: 2002-12-08
Posts: 12
Website

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!

Offline

 

#2 2002-12-08 12:24:01 pm

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Converting Paths

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

Applescript:

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

Offline

 

#3 2002-12-08 01:04:32 pm

JBadger
Member
From:: Calgary, Alberta
Registered: 2002-12-08
Posts: 12
Website

Re: Converting Paths

Thanks, it works perfect!

Offline

 

#4 2002-12-08 01:09:40 pm

T.J. Mahaffey
Administrator
From:: Arkansas, USA
Registered: 2002-11-20
Posts: 238
Website

Re: Converting Paths

Yep. There is another way, but I couldn't say whether or not it was "better". wink

Text Item Delimiters to the rescue!

Applescript:

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 ""


T.J.
tj@tjmahaffey.com

Offline

 

#5 2002-12-09 09:16:21 am

face
Member
From:: Tucson, AZ
Registered: 2002-12-07
Posts: 1

Re: Converting Paths

how about this...works on my 10.2.2 system

Applescript:


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

Offline

 

#6 2002-12-09 09:45:24 am

T.J. Mahaffey
Administrator
From:: Arkansas, USA
Registered: 2002-11-20
Posts: 238
Website

Re: Converting Paths

Brilliant!

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

Applescript:

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


T.J.
tj@tjmahaffey.com

Offline

 

#7 2003-01-06 01:04:44 am

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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.


--
Jean-Baptiste LE STANG

Offline

 

#8 2003-01-06 02:39:18 pm

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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

Applescript:


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

Applescript:


(*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 :=))


--
Jean-Baptiste LE STANG

Offline

 

#9 2003-01-06 03:20:46 pm

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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


--
Jean-Baptiste LE STANG

Offline

 

#10 2003-01-07 01:03:57 am

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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 ''.

Applescript:


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


--
Jean-Baptiste LE STANG

Offline

 

#11 2003-01-07 06:30:28 am

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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


--
Jean-Baptiste LE STANG

Offline

 

#12 2003-01-07 01:46:40 pm

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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 :=))


--
Jean-Baptiste LE STANG

Offline

 

#13 2003-01-07 01:55:41 pm

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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


--
Jean-Baptiste LE STANG

Offline

 

#14 2003-01-13 01:57:12 pm

andy_boretto
Member
Registered: 2003-01-02
Posts: 28

Re: Converting Paths

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


it's quoted form



Applescript:


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


I am not speaking for my employer.  These views are my own

Offline

 

#15 2003-01-13 02:33:42 pm

Jean-Baptiste LE STANG
Member
From:: Paris
Registered: 2002-11-20
Posts: 167

Re: Converting Paths

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


--
Jean-Baptiste LE STANG

Offline

 

#16 2003-01-13 02:39:57 pm

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Converting Paths

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?

Offline

 

#17 2003-01-13 02:43:06 pm

andy_boretto
Member
Registered: 2003-01-02
Posts: 28

Re: Converting Paths

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




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


bad bad bad dictionary people.


I am not speaking for my employer.  These views are my own

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)