Re: File URL to Alias?
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: |
_______________________________________________
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