• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Converting Unix path to AppleScript path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting Unix path to AppleScript path


  • Subject: Re: Converting Unix path to AppleScript path
  • From: has <email@hidden>
  • Date: Tue, 28 Mar 2006 14:06:37 +0100

Ed Stockly wrote:

>I'm looking for a simpler and more reliable way to convert a UNIX style path (read from an XML file) to an appleScript style path (file "volume:directory:directory:file.ext" or alias "volume:directory:directory:file.ext")
>[...]
>"file:///Volumes/Mag_Production/Color Lab Images/03:26/Issue #9 prepressed/tm.0326.chinaRS.tiff"

That's not a POSIX path, that's a URL. Extracting the POSIX path portion is easy enough:

on urlToPOSIXPath(theURL)
   -- Extract and decode a URL's path component (ignores network location, etc.)
   return do shell script "python -c 'import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])' " & quoted form of theURL
end urlToPOSIXPath

So to convert the URL string to a POSIX file object:

on urlToPOSIXFile(theURL)
   return POSIX file urlToPOSIXPath(theURL)
end urlToPOSIXFile

Note that if the drive isn't mounted then the HFS path bit'll look wrong (AS mucks up HFS<->POSIX path conversions), but the POSIX file value itself should be correct.

has

p.s. If you need to keep the original URL intact, write the URL string to a temp file as «class utf8» then read it back as «class furl». But for most tasks the above is simplest.
--
http://freespace.virgin.net/hamish.sanderson/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Setting password of a keychain key
  • Next by Date: Re: Setting password of a keychain key
  • Previous by thread: Re: Converting Unix path to AppleScript path
  • Next by thread: RE: Converting Unix path to AppleScript path
  • Index(es):
    • Date
    • Thread