Why doesn't this link open the folder when clicked in Safari?

Hi! :slight_smile:

 <a href="file://localhost/Users/McUsr/Documents/Computers/Operating%20Systems/Os%20X/">Computer/Operating Systems/Mac Os X</a>

When clicking the link above, I really expect the file url to be passed over to finder via Launch Services.

I wonder if someone knows why it doesn’t happen, and what I have to do to make it happen.

(Without making a special protocol, I’d really appreciate using the file:// url if that is possible.)

Thanks!

Why don’t you leave localhost out, because it depends on how localhost is defined in /etc/hosts.

file:///Users/mcusr/… is a good file url and works on my machine (using it for years)

Hello. :slight_smile:

Thanks for your answer, but it really doesn’t work on my machine. I guess I have “customized” something, with a side effect!

I was thinking of this as I woke up, and why not just make another protocol? :slight_smile: And then I can figure it out while I have the benefits!

You know for sure when the following code won’t run

set theFile to POSIX path of (choose folder) as string

set AppleScript's text item delimiters to "/"
set textItems to every text item of theFile
set AppleScript's text item delimiters to linefeed
set t to do shell script "/bin/echo -n " & quoted form of (textItems as string) & " | php -r 'while(($line=fgets(STDIN)) !== false){echo  rawurlencode(trim($line)) . \"\\n\";}; '" without altering line endings
set AppleScript's text item delimiters to "/"
set theFileURL to ({"file:", ""} & every paragraph of t) as string
set AppleScript's text item delimiters to ""

do shell script "open " & theFileURL

Thanks!

I don’t have to run that, a terminal command like open ‘file://localhost/Users/McUsr/Desktop/’ (disregarding any misspelling at this moment) works just great! (Edit : Your code prodcuced the same result! :slight_smile:

The problem is when I click the link from within Safari, it just stays there, like it has a launch serverices of its own! And that behaviour is really ok for other file types, like png, or what have you, but then again, nothing happens when I click on a folder.

It is also funny, that url schemes like http and https are specified in RCDefaults.app’s preference pane, but nothing for file. Maybe file is “hardwired”?

( I can’t make this work either: Make Safari open links from applications in the current space - Mac OS X Hints )

So now I am reading Launch Services Programming Guide: Introduction hoping to become wiser!

Edit++

I have no time to meddle with Safari at the moment, trying to understand why, so I just make a protocol, I script the insertions of the furl’s anyway! I anybody has any clue, to as how to circumvent this in Safari, it would be highly appreciated! :slight_smile:

And Safari has indeed specified file as one of its url schemes in the property list file, no wonder it isn’t working, so nothing using this scheme is bypassed to launch services but handled internally!

Now I wonder if it is like that just for me, or for all people.

The problem with that particular folder, was that the permissions for it, differed from the normal permissions on folders. It took almost three hours to figure that out!

So, when folders doesn’t open as they should when clicked onto urls in Safari, it is time to check the permissions of that folder! (Lesson learned!)

Well, it wasn’t the permission of that folder after all, as I have fixed that issue. it is kind of ironic!

I had finder encode the url for me with the following code:


tell application "Finder"
    get URL of folder (selection as alias)
    log result
end tell

And I edited away the “localhost”, and it still didn’t work, so, my conclusion is that spaces in foldernames, that is to be opened via furls in Safari, is to be avoided alltogether.

I am happy to report that this works very well: :slight_smile:

file://localhost/Users/McUsr/Documents/Computers/Operating_Systems/

And this works even better, as Safari really reveals the item!

file://localhost/Users/McUsr/Documents/Computers/Operating_Systems/.DS_Store

I can understand that the .DS_Store file may be an obstacle for people that shares files with other platforms, but I see just benefits from it when going native. I use it to stand on when creating new folders, and now this, if I have been there in a finder window, then it is there! :slight_smile:

Snow Leopard has the best editon of Websters, what regards detail, as many of the word definition pages disappeared in Lion.