Re: getting a file by URL ?
Re: getting a file by URL ?
- Subject: Re: getting a file by URL ?
- From: Thomas Fischer <email@hidden>
- Date: Wed, 2 Jun 2010 10:38:19 +0200
Hello,
Am 01.06.2010 um 16:45 schrieb email@hidden:
>> the point is that it is not clear what a "URL" is on the Mac or for AppleScript, if it isn't defined someplace – and I didn't find it.
>> And since at least Safari, Mozilla, Opera and TextWrangler are scriptable, there may arise some confusion.
>> It seems, that the Opera and IE version doesn't always work (without System Events):
>
>
> Look in the Standard Additions dictionary:
> …
I looked at the "System Events" or "Finder" dictionary, where URL is a property of a disk item or an item respectively:
URL (text, r/o) : the URL of the [disk] item
and was testing its usefulness.
Turns out that (like rather often in AppleScript) it is somewhat confusing.
It remains obscure why the Standard Additions claim
> file URL (obsolete)
when it is used as a regular property in "System Events" and Finder.
Both give the URL as
"file://localhost/Users/Thomas/Desktop/New Folder/My Test.txt",
so I suppose that this should be "the URL" of a disk item.
After checking for typos I also find that
"file://localhost/Users/Thomas/Desktop/New Folder/My Test.txt" (file: + two slashes + localhost)
and
"file:///Users/Thomas/Desktop/New Folder/My Test.txt" (file: + three slashes)
will yield identical results, so at least this seems to be consistent.
But AppleScript will not decode the URL-escaped characters, so you can get there, but there is no way back inside AppleScript. You have to use some of the solutions suggested like the satimage osax or Python.
There are numerous ways of identifying Finder items (files, folders, applications):
– Finder paths: folder "Desktop" of folder "Thomas" of folder "Users" of startup disk of application "Finder" (from Finder)
– classic paths: folder "Macintosh HD:Users:Thomas:Desktop:" (from "System Events")
– POSIX paths: "/Users/Thomas/Desktop/" (from Standard Additons)
– URL: "file://localhost/Users/Thomas/Desktop/addDate.app/"
with again subtle differences between different version, e..g. if myTest is the alias to an application or folder,
get POSIX path of myTest
will use Standard Additions and yield a slash at the end, while
tell application "System Events" to get the POSIX path of myTest
will not.
I am struggling for a while with the problem that parts of AppleScript (e.g. the do shell script) require POSIX paths while others (e.g. the Finder) need classic paths, and it is not always easy to handle this (e.g. when you drop files and/or folders on a script and you have to deal with the aliases).
Thus this is on my side a more theoretical discussion about the possible use of URLs to deal with the problem, to get rid of some rather awkward workarounds I use.
Hence the answer to the original question
> does anyone know a way to locate a file by URL, such as
> "file://localhost/Users/richardr/Desktop/bevakad/NORRSÄTRASKOLAN_mall_A4_2010/"
> and turn that into an alias/ posix file etc.
> Preferably in vanilla AppleScript,…
seems to be: "No".
And along the way came the curious result that "System Events"
will handle
get POSIX path of (file "Macintosh HD:Users:Thomas:Desktop:Test.txt")
and
set myFile to POSIX file "file://localhost/Users/Thomas/Desktop/Test.txt"
correctly, but not the next call
get POSIX path of myFile
with the events pane showing
get POSIX path of file "Macintosh HD:Users:Thomas:Desktop:Test.txt"
--> "/Users/Thomas/Desktop/Test.txt"
get POSIX path of file "Macintosh HD:Users:Thomas:Desktop:Test.txt"
--> error number -1700 from «class posx» of file "Macintosh HD:Users:Thomas:Desktop:Test.txt" to reference
Standard Additions (i.e the absence of a tell "System Events" handler) will give correct results.
So much for now!
Thomas
_______________________________________________
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