• 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: File URL to Alias?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File URL to Alias?


  • Subject: Re: File URL to Alias?
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 25 Feb 2014 22:32:09 +1100

On 25 Feb 2014, at 10:12 am, Shane Stanley <email@hidden> wrote:

use framework "Foundation"
on pathFromTextURL:theURL
set thePath to current application's NSString's stringWithString:theURL -- make an NSString
set thePath to thePath's stringByReplacingPercentEscapesUsingEncoding:(current application's NSUTF8StringEncoding) -- replace encoded chars
set theStart to location of (thePath's rangeOfString:"/") -- find / to reomve file: bit
return (thePath's substringFromIndex:theStart) as text
end pathFromTextURL:

I was asked off-list about how this would cope with URLs beginning with "file//localhost". The answer is, not very well. In my defence, URLs created under Mavericks no longer include localhost.

But I realised there's an easier method than the above, which shouldn't care about localhost or the extra slashes:

use framework "Foundation"
on pathFromTextURL:theURL
return (current application's NSURL's URLWithString:theURL)'s |path|() as text
end pathFromTextURL:

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: File URL to Alias?
      • From: "koenig.yvan" <email@hidden>
References: 
 >File URL to Alias? (From: Christopher Stone <email@hidden>)
 >Re: File URL to Alias? (From: "koenig.yvan" <email@hidden>)
 >Re: File URL to Alias? (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: How can I delete every empty row of an Excel document?
  • Next by Date: Re: File URL to Alias?
  • Previous by thread: Re: File URL to Alias?
  • Next by thread: Re: File URL to Alias?
  • Index(es):
    • Date
    • Thread