Dead weblocs

For one of my projects I checked in my .webloc files into my subversion repository. It was a really bad idea. The web locations are stored in the resource fork which will be lost after check-in. No chance to recover them :(

If you wish to share your web shortcuts you should use .url files that are common in Windows. Safari is able to read them too. So there’s no obstacle anymore to share your web shortcuts.

The format of the content of such a file is very simple:

[InternetShortcut]
URL=http://www.example.com

You should add a closing line feed, otherwise some browsers open an empty tab.
I found a script written by Joachim Bondo that converts .webloc into .url files.


property devToolsPath : "/Developer/Tools/" -- path to free Apple Developer Tools

on open draggedFiles
  local theFile, weblocPath, urlPath, theURL, cmd
  repeat with theFile in draggedFiles
    if (theFile as string) ends with ".webloc" then
      -- get full paths
      set weblocPath to quoted form of POSIX path of theFile
      set urlPath to text 1 thru -9 of weblocPath & ".url'"
      -- 1) get URL from .webloc file
      set cmd to devToolsPath & "DeRez -e -only 'url ' " & weblocPath & ¬
        " | grep '/* .* */' | sed 's/^.*/* //;s/ */$//' | tr -d 'n'"
      set theURL to do shell script cmd
      if theURL begins with "http" then
        -- 2) write URL to file
        set cmd to "echo '[InternetShortcut]" & (ASCII character 10) & ¬
          "URL=" & theURL & "' > " & weblocPath
        do shell script cmd
        -- 3) rename file using MvMac now that we have Developer Tools anyway
        set cmd to devToolsPath & "MvMac " & weblocPath & " " & urlPath
        do shell script cmd
      end if
    end if
  end repeat
end open

If you just want to get the address from the .webloc file you can use the script from this site:


set the_file to choose file
try
    tell application "Finder"
        set the_location to location of file the_file
        display dialog the_location buttons {"OK"} default button 1
    end tell
end try

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>