Mac OS X - some .weblocs files open in Firefox, some don't - why?

0

I've changed the default application for opening .webloc files to Firefox (using RCDefaultApp, nice piece of kit, that) and that's all fine, except for one bit of weirdness. If I create a .webloc using a script (I'm using a Perl script adapted from this one to create spotlight-searchable bookmarks) then it opens up in Firefox as a bit of unstyled XML (with the "This XML file does not appear to have any style information associated with it. The document tree is shown below" header).

Now here's the weirdness: if I drag a URL from the Firefox URL bar onto the desktop, I get a .webloc file that is opened by Firefox with no problems - but when I look at the contents it's completely identical to the one I created with my script. It has to be something to do with the file creator - if I open the Firefox-created .webloc file and then save it from a text editor, it no longer works.

So what's going on? How do two identical bits of XML open differently depending on how they were created? Is there some magic bit somewhere I can change?

For reference, here is the contents of a .webloc file as created by my script (I'd put the one created by Firefox as well, but since it's completely identical (I checked with diff) there's no point):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>URL</key>
        <string>http://www.spacetelescope.org/</string>
    </dict>
</plist>

stib

Posted 2011-06-29T04:29:53.997

Reputation: 3 320

1My guess is that one of the files (probably the one created by firefox) has an extended attribute that's controlling this. You can list xattrs with ls -l@ /path/to/file, and show their contents with xattr -l /path/to/file. – Gordon Davisson – 2011-06-29T09:03:28.967

Answers

5

Although the two webloc files look the same they are not. When you drag a URL to the Desktop, the system creates a webloc file with a hidden resource fork. You can reveal the resource fork of a file using the derez command in the terminal:

derez /Users/<User Directory>/Desktop/ESA-Hubble.webloc

For your example URL the resource fork is:

data 'drag' (128) {
$"0000 0001 0000 0000 0000 0000 0000 0003"            /* ................ */
$"5445 5854 0000 0100 0000 0000 0000 0000"            /* TEXT............ */
$"7572 6C20 0000 0100 0000 0000 0000 0000"            /* url ............ */
$"7572 6C6E 0000 0100 0000 0000 0000 0000"            /* urln............ */
};

data 'url ' (256) {
$"6874 7470 3A2F 2F77 7777 2E73 7061 6365"            /* http://www.space */
$"7465 6C65 7363 6F70 652E 6F72 672F"                 /* telescope.org/ */
};

data 'TEXT' (256) {
$"6874 7470 3A2F 2F77 7777 2E73 7061 6365"            /* http://www.space */
$"7465 6C65 7363 6F70 652E 6F72 672F"                 /* telescope.org/ */
};

data 'urln' (256) {
$"4553 412F 4875 6262 6C65"                           /* ESA/Hubble */
};

Earlier in OS X, webloc files were just empty files with resource fork information. At some point webloc files were "modernized" to contained property list data, but the resource fork information was not dropped.

This means that some programs can be patchy in their support for weblocs i.e. sometimes working with the property list and sometimes working with the resource fork.

Maybe a bug can be filed with Firefox, requesting support for property list based weblocs?

David Kennedy of Zenopolis

Posted 2011-06-29T04:29:53.997

Reputation: 451

Lordy, I thought resource forks were left behind with system 9. I remember the fun I used to have with resEdit back in the day… Thanks for the info - I will file that bug. – stib – 2011-06-30T00:47:20.437

Ok, I've been having a look at Rez and DeRez, but I can't find any info on actually creating resource forks. Any ideas? – stib – 2011-06-30T01:42:56.840

I did find out that you can actually see the resource fork of a file eg "somefile" by doing cat somefile/rsrc And the reverse is true you can simply echo stuff into the resource fork - so when I did 'cat working.webloc/rsrc > non-working.webloc/rsrc' it put the resource fork of the first webloc into the second. What I want to do now is to be able to edit the resource with my perl script or shell script. – stib – 2011-06-30T01:51:15.010

I'm more of an Objective-C coder, I'm not sure how to accomplish this using scripts. Can you have your script write out a url file instead? These files have a ".url" extension and contain the text: "[InternetShortcut]\r\nURL=%@\r\n" where \r represents the "return" character, \n represents the "newline" character and %@ represents the url you want to store. – David Kennedy of Zenopolis – 2011-06-30T09:38:35.047

I had a go with that. By default the .url file opened with safari, but if I tried opening it with FF it just showed me the contents of the text file. I'm off to file another bug. In the mean time I've made an applescript to read .url files and open them with FF, which is a lot kludgier than I hoped this to be. Still I've acheived my ultimate goal - having my bookmarks appear in Spotlight. – stib – 2011-07-01T03:44:42.673