• 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: getting a file by URL ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting a file by URL ?


  • Subject: Re: getting a file by URL ?
  • From: Thomas Fischer <email@hidden>
  • Date: Tue, 1 Jun 2010 10:15:41 +0200

Hi Mark,

my first problem is what AppleScript considers a URL:

When I open a file on my desktop with different software, I get the following results:

Safari and other WebKit browsers, Mozilla:
file:///Users/Thomas/Desktop/New Folder/My Test.txt
(shown as file:///Users/Thomas/Desktop/New Folder/My Test.txt in Firefox 3.x)

Internet Explorer, Opera:
file://localhost/Users/Thomas/Desktop/New Folder/My Test.txt

Amaya:
/Users/Thomas/Desktop/New Folder/My Test.txt

TextWrangler:
file:///Macintosh HD/Users/Thomas/Desktop/New Folder/My Test.txt

I used TextWrangler's URL for my last example, obviously AppleScript isn't happy with that.


The second problem is with the identification of the file and its path.
Particularly lovely are Script Editor's result messages:

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

where both requests are inside a "System Events" call, the first from

get POSIX path of (file "Macintosh HD:Users:Thomas:Desktop:Test.txt")

and the second from

set myFile to POSIX file "file:///Users/Thomas/Desktop/Test.txt"
log "myFile: " & myFile
get POSIX path of myFile

where the log command yields

(*myFile: Macintosh HD:Users:Thomas:Desktop:Test.txt*)

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.

By the way, hovering the mouse pointer over "file" in "POSIX path of file" of the result and error messages above reveals strange differences:
 
'core'\'getd'{'----':obj '{ 'form':'prop','want':'prop', 'seld':'posx', 'from':'obj '{ 'form':'name', 'want':'file', 'seld':'utxt'("Macintosh HD:Users:Thomas:Desktop:Test.txt"), 'from':'null'0 } }, &'csig':'65536 }

for the successful and

'core'\'getd'{'----':obj '{ 'form':'prop','want':'prop', 'seld':'posx', 'from':'furl'("file:///localhost/Users/Thomas/Desktop/Test.txt") }, &'csig':'65536 }

for the failing command.

This leaves me puzzled:

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"?

(By the way, does anybody know a way to copy the Apple Event transcript that shows when hovering over AppleScript results in AppleScript Editor?)

Thomas Fischer


Am 30.05.2010 um 22:06 schrieb Mark J. Reed:

file:///Macintosh HD is an invalid path.  In POSIX/URL land, the boot volume's name is nowhere to be seen; POSIX file "/" and POSIX file "file:///" both refer to HFS file "Macintosh HD:" (or whatever your boot volume's name is).

OMM (10.6.3), the indirect version with the variable works fine. 




On Sun, May 30, 2010 at 3:38 PM, Thomas Fischer <fischer.th@aon.at> wrote:
Hi Mark,

I don't get your suggestion to work:

tell application "System Events"
try
set myURL to "file:///Macintosh HD/Users/Thomas/Desktop/Test.txt"
set myFile to POSIX file myURL
end try
set myFile to POSIX file "file:///Macintosh HD/Users/Thomas/Desktop/Test.txt"
log myFile
get POSIX path of myFile
end tell

results in

tell application "System Events"
get POSIX file "file:///Macintosh HD/Users/Thomas/Desktop/Test.txt"
--> error number -1728 from POSIX file "file:///Macintosh HD/Users/Thomas/Desktop/Test.txt"
(*file Macintosh HD:Macintosh HD:Users:Thomas:Desktop:Test.txt*)
get POSIX path of file "Macintosh HD:Macintosh HD:Users:Thomas:Desktop:Test.txt"
--> error number -1700 from «class posx» of file "Macintosh HD:Macintosh HD:Users:Thomas:Desktop:Test.txt" to reference

So the first problem is:

System Elends accepts
set myFile to POSIX file "file:///Macintosh HD/Users/Thomas/Desktop/Test.txt"
but not 
set myURL to "file:///Macintosh HD/Users/Thomas/Desktop/Test.txt"
set myFile to POSIX file myURL
which I find strange.

And then the result of the POSIX file command is
file Macintosh HD:Macintosh HD:Users:Thomas:Desktop:Test.txt
which obviously won't word because of the double "Macintosh HD".

Or am I doing it wrong?

Emmanuel's satimage osax solutions work OK, however.

Thomas


Am 30.05.2010 um 20:53 schrieb Mark J. Reed:

POSIX file works with file URLs; in fact, the class of a POSIX file specifier is «class furl».

POSIX file "file://localhost/Users/richardr/Desktop/bevakad/NORRSÄTRASKOLAN_mall_
A4_2010/"

Should work as-is with System Events; add "as alias" if you intend to use it with the Finder.


On Sun, May 30, 2010 at 1:22 PM, Emmanuel LEVY <email@hidden> wrote:
satimage osax' absoluteurl command is good at that

Emmanuel



On May 30, 2010, at 6:44 PM, Richard Rönnbäck wrote:

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, as shell scripting seems to have some
encoding issues with decomposed/precomposed unicode characters



_______________________________________________
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

_______________________________________________
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



--
Mark J. Reed <email@hidden>

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)

Archives: http://lists.apple.com/archives/applescript-users

This email sent to fischer.th@aon.at


 _______________________________________________
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



--
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

  • Follow-Ups:
    • Re: getting a file by URL ?
      • From: Axel Luttgens <email@hidden>
    • Re: getting a file by URL ?
      • From: "Mark J. Reed" <email@hidden>
  • Next by Date: Re: getting a file by URL ?
  • Next by thread: Re: getting a file by URL ?
  • Index(es):
    • Date
    • Thread