• 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: "koenig.yvan" <email@hidden>
  • Date: Tue, 25 Feb 2014 14:21:35 +0100


Le 25/02/2014 à 12:32, Shane Stanley <email@hidden> a écrit :

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

No need for « defence » Shane.

In fact, URLs created under Mavericks are supposed to no longer include localhost.

It seems that the problem is not a system one but an application one.

Numbers 2.3 returns
"file://localhost/Users/yvankoenig/Desktop/beurk.numbers"
TextWrangler 4.5.6 returns
"file://localhost/Users/yvankoenig/Desktop/beurk.txt"
SketchBook Pro 5.5.6 returns
"file://localhost/Users/yvankoenig/Desktop/beurk.tif"
VLC 2.1.4 returns
"file://localhost/Users/yvankoenig/Desktop/JJLv1.mp4"


But Numbers 3.1 returns
"file:///Users/yvankoenig/Desktop/beurk.numbers"
File Viewer 1.4 returns
"file:///Users/yvankoenig/Desktop/JJLv1.mp4"
TextEdit 1.9 returns
"file:///Users/yvankoenig/Desktop/beurk.txt"


Of course, the late code treat well both cases.


Yvan KOENIG (VALLAURIS, France) mardi 25 février 2014 14:19:36






 _______________________________________________
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: Alex Zavatone <email@hidden>
    • Re: File URL to Alias?
      • From: Ron Hunsinger <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>)
 >Re: File URL to Alias? (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: File URL to Alias?
  • Next by Date: Excel scripts
  • Previous by thread: Re: File URL to Alias?
  • Next by thread: Re: File URL to Alias?
  • Index(es):
    • Date
    • Thread