Re: getting a file by URL ?
Re: getting a file by URL ?
- Subject: Re: getting a file by URL ?
- From: Tommy Bollman <email@hidden>
- Date: Wed, 2 Jun 2010 17:24:52 +0200
On 2. juni 2010, at 16.47, Axel Luttgens wrote:
>
> Le 2 juin 2010 à 10:38:19, Thomas Fischer a écrit :
>
>> [...]
>>
>> 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)
>
> Note that the Finder allows for "classic paths" as well; for example:
> folder "Desktop" of folder "Macintosh HD:Users:Thomas"
>
>
>> – classic paths: folder "Macintosh HD:Users:Thomas:Desktop:" (from "System Events")
>
> Or from the Finder as seen above, or from Standard Additions as in:
> alias "Macintosh HD:Users:Thomas:Desktop:"
>
>
>> – POSIX paths: "/Users/Thomas/Desktop/" (from Standard Additions)
>
> Or even from System Events, e.g.:
> folder "/Users/Thomas/Desktop"
> Even if not explicitly stated (unless I've been unable to find the official info), most "modern" apps tend to understand posix paths for building their own references.
>
>
>> – URL: "file://localhost/Users/Thomas/Desktop/addDate.app/"
>
> Yup. That one seems to be the less useful one for practical purposes. ;-)
> Anyway, it appears that the other ways already provide some generality.
>
>
>> 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.
>
> Yes, this is not entirely consistent. You could have a look at:
> http://lists.apple.com/archives/AppleScript-Users/2008/Dec/msg00456.html
>
>
>> 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).
>
> In that case, one already has alias references, and such references should be directly useable by any scriptable application dealing with files/folders: in some way, alias references behave as a least common denominator in the AppleScript world. There should thus be no need to build other references from scratch, with the help of textual paths. Of course, textual paths are needed for shell scripts, but this is immediately done by taking the POSIX path property from the alias references.
>
> That said, aliases aren't native, and references created in an application shouldn't be systematically coerced into aliases "just in case" if they are to be used in that application only.
>
>
>> 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
>
> If you run this one
>
> tell application "System Events"
> set F to file "Macintosh HD:Users:Thomas:Desktop:Test.txt"
> set PF POSIX file "/Users/Thomas/Desktop/Test.txt"
> end
>
> and have a look at the log, it appears that:
>
> - the first statement yields an item of class "file" that is, a System Events reference
> - the second statement doesn't even reach System Events, and yields an item of class «class furl».
>
> PF thus contains a file reference similar to one that would have been obtained with Standard Addition's "choose file name" command; and System Events just doesn't know anything about such references.
>
> As a result, when running:
>
> tell application "System Events"
> POSIX path of POSIX file "/Users/Thomas/Desktop/Test.txt"
> end
>
> System Events tries to fetch the POSIX path property, as understood by it ('posx'), from an object that doesn't have such a property.
>
> You could resort to:
>
> tell application "System Events"
> «class psxp» of POSIX file "/Users/Thomas/Desktop/Test.txt"
> end
>
> provided you never recompile that script.
> But then, doesn't this one just do the job:
>
> POSIX path of POSIX file "/Users/Thomas/Desktop/Test.txt"
>
> in a much nicer and easier way?
> :-)
>
> Axel
>
>
> _______________________________________________
> 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
>
I would say that the file Urls are interesting if say you are hosting your private site, and want's to suck out the page you are currently viewing for editing. Chrome I believe would show such a page as a "localhost" url.
Then it would have been interesting for me to open that Url I already got instead of having to convert it before telling
BBEdit to open it.
Just for your information.
Best regards
Tommy Bollman
--------------------------------------------------------------------------------------------------
Mollison's Bureaucracy Hypothesis:
If an idea can survive a bureaucratic review
and be implemented it wasn't worth doing.
_______________________________________________
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