• 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: Wed, 29 Mar 2006 12:57:15 +0100

Matt Deatherage wrote:

>I personally believe that any of these are faster and more efficient
>than spawning an _entire shell and Python interpreter_ for decoding two
>hexadecimal digits.  I'm like that, though, and your mileage may vary.

The OP asked for something that was simple and reliable, not "As fast as dammit, and who cares if it's right!" If the *only* thing you care about is how quick your scripts run, then you can save a huge amount of time and trouble by writing them all as:

on run
end run -- Superfast!!!!

There are plenty ways to make code go faster if necessary, but until the author has got their code tested and working correctly and can start profiling it to identify the *actual* performance bottlenecks, it's pointless (or even counterproductive) worrying about it.

(Though heck, obsessing about raw speed in AppleScript is a completely lost cause anyway when it's one of the slowest and least efficient languages around. If performance really is that big a concern, go use a better language already.)


But since you're concerned about my original solution's speed, here's another solution using TextCommands' [1] 'decode URL' command (which not only works correctly but is also several times faster than that guidebook garbage):

tell application "TextCommands"
    -- theURL should be a valid file URL string
    set posixPath to decode URL (search theURL for "^file://[^/]*(.*)" with regex)
end tell

Alternatively, you could wrap the original Python script in a scriptable faceless background application using the same toolkit that TextCommands is written in, eliminating the overheads of using 'do shell script':

import urllib, urlparse, macfile

def urlToPOSIXFile(url):
   return macfile.File(urllib.unquote(urlparse.urlparse(url.encode('utf8'))[2]).decode('utf8'))

installeventhandler(
      urlToPOSIXFile,
      'SomeCode', # an 8-character Apple event code
      ('----', 'url', kAE.typeUnicodeText)
      )

Or, if you're not afraid of a bit of C, you could write a 10-line scripting addition that uses a couple of Core Foundation calls to convert the URL into a POSIX path.

So there's no shortage of "fast" solutions that are also *correct*, should something a little bit speedier really be needed.

has

[1] http://osaxen.com/files/textcommands1.0.1.html
--
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

  • Follow-Ups:
    • Re: Converting Unix path to AppleScript path
      • From: Martin Orpen <email@hidden>
  • Prev by Date: Re: badly decomposed
  • Next by Date: Re: Converting Unix path to AppleScript path
  • Previous by thread: RE: Converting Unix path to AppleScript path
  • Next by thread: Re: Converting Unix path to AppleScript path
  • Index(es):
    • Date
    • Thread