Search code examples
objective-ccocoamacosmacos-carbon

Crafting .webloc file


I'm writing a program (for Mac OS X, using Objective-C) and I need to create a bunch of .webloc files programmatically.

The .webloc file is simply file which is created after you drag-n-drop an URL from Safari's location bar to some folder.

Generally speaking, I need an approach to create items in a filesystem which point to some location in the Web. As I understand .webloc files should be used for this on Mac OS X.

So, is it possible to craft a .webloc file having a valid url and some title for it?


Solution

  • It is little known - but there is also a simple plist based file format for weblocs.

    When creating webloc files you DO NOT NEED to save them using the resource method the other three posters describe. You can also write a simple plist:

    <?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://apple.com</string>
    </dict>
    </plist>
    

    The binary resource format is still in active use and if you want to read a plist file - then sure you need to read both file formats. But when writing the file - use the plist based format - it is a lot easier.