Re: getting a file by URL ?
Re: getting a file by URL ?
- Subject: Re: getting a file by URL ?
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 1 Jun 2010 06:53:37 -0400
On Tue, Jun 1, 2010 at 4:15 AM, Thomas Fischer <email@hidden> wrote:
> my first problem is what AppleScript considers a URL:
Precision, please. The problem you are demonstrating is that
different applications will generate different paths/URLs for the same
file. That's hardly AppleScript's fault.
> TextWrangler:
> file:///Macintosh HD/Users/Thomas/Desktop/New Folder/My Test.txt
TextWrangler is going well against the grain here. Perhaps its
treatment of file URLs is a leftover from pre-X Mac OS.
As to your second problem, you identified it here:
> where both requests are inside a "System Events" call,
Ah! By "call" here, do you mean the code is inside a 'tell
application "System Events"'? That would be the source of your
difficulties. I don't know what «class posx» is, or why System
Events' vocabulary interferes with the normal interpretation of 'POSIX
path', but it does. It may be that you have found a bug.
(Having a difference when using a variable vs a literal is not
uncommon in AS, where the compiler does as much work ahead of time as
it can.)
Simply moving the "get POSIX path of myFile" outside the tell block
removes the error, but I would get rid of the tell block entirely -
it's totally unnecessary in this case. As a general rule, you want
to use tell blocks only when necessary and make them as small as
possible.
> All of this gets more confusing if I start with
> "file:///Users/Thomas/Desktop/New Folder/My Test.txt"
> where the " " may or may not be evaluated by System Events, it seems it rather isn't.
Indeed, it seems that "POSIX file" does not expand %-encoded bytes in
URL's. That would also seem to be a bug.
> By the way, hovering the mouse pointer over "file" in "POSIX path of file" of the result and error messages above reveals strange differences:
What are you talking about here? The 'POSIX path of file' bit
doesn't even appear in the result and error logs in AppleScript Editor
OMM, and hovering the mouse over the code doesn't show anything of the
sort. What editor program are you using? Do you have a plug-in?
> set myFile to POSIX file "file:///Users/Thomas/Desktop/Test.txt"
> log "myFile: " & myFile
> --> (*myFile: Macintosh HD:Users:Thomas:Desktop:Test.txt*)
> get POSIX path of myFile
> How can myFile in the last line have the value "file:///localhost/Users/Thomas/Desktop/Test.txt"?
It doesn't. Are you saying you want it to? "POSIX file" may accept
URLs, but "POSIX path of" will not yield one. You can use satimage or
generate one yourself by string concatenation: ' "file://" & (POSIX
path of myFile)' will work except for the lack of %-encoding.
--
Mark J. Reed <email@hidden>
_______________________________________________
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