Folder action/.webloc conversion help?

Hey all, I’ve seen a couple of hints that have pieces of what I need, but none has totally done the trick. Here’s my dilemma:

I have a report that needs to be generated on a monthly basis, which would consist of a single text file containing the URLs extracted from individual .webloc files. The application (sorry, can’t say which, though it shouldn’t have any bearing on my request) generates .webloc files as its method of tracking recently visited pages/URLs. It stores them as individual .webloc files in /private/var/tmp/folders.50x/TemporaryItems/TempBookmarksXXXXX, where XXXXX is a randomly generated 3-5 digit number. The app creates a new TempBookmarks folder after each launch, but only when it has a newly opened file to add to its list. It leaves the previous folder untouched until the computer restarts and purges all old temp data.

It looks like I could easily create a folder action in Automator that can copy the contents of a folder to another location. The roadblocks I see are that:

a) the .webloc files are in an invisible path
b) the TempBookmarks folder names change on each launch so I’d guess that it’s not possible to attach a folder script
c) though I’ve seen several hints about converting .webloc files to .url files, I haven’t seen any way to convert the file’s URL to text. .webloc files are binary so in my tinkering, Automator has only been able to launch the .webloc or grab the filename… neither of which is very helpful.

Ideally, this would be a two step process… collection then, on some other date, conversion/text file generation like so:

  1. Copy newly added .webloc files to a new folder with the day’s date
  2. On a later date when the report needed to be generated, drop the folders corresponding the needed reporting dates and use a droplet to convert/extract the URLs, append the resulting text to the same text file, with each URL on a separate line, open the, compose a new message, attach the file, then cook me dinner. :wink:

So, that’s pretty much it. Please someone tell me if I’m crazy and this is impossible or if I’ve overlooked some totally obvious solution… it wouldn’t be the first time. :slight_smile:


P.S. The application DOES have the ability to run a script on startup, but not on quitting.

P.P.S. If it helps, I also have BBEdit installed which I noticed is Automator-enabled.

Sure it’s possible. Create the new folder with the shortform date as its name. Use an AppleScript scriptlet (Automator will accept those) containing a “do shell script…” statement that copies the files to the new folder (in a visible directory). You’re not specific enough about “newly added” to know how to distinguish them from whatever else is in the hidden directory, and don’t make clear whether you want to “move” the files or “copy” them - not the same thing.

If you try to open a webloc in BBEdit, say, your browser will simply open that URL, and BBEdit won’t show the contents. To read out the file you either have to inhale the XML to a script and extract the URL from the XML, or set the extension of the .weblocs to .txt and then open them - only the URL will show then (in BBEdit).

Not hard to do, but not trivial either.

I’m glad to know that this isn’t an impossible task. Since I’m a total newbie to scripting, I’m looking for as much help as possible. I’ve done a bit of tinkering with Automator and it seems pretty easy to create an action that will copy new files to a new, dated folder.

In another forum, it was suggested that I attach folder action “X” to TemporaryItems that would attach folder action “Y” to any new folders created inside it whose name begins with, “TempBookmarks”. I don’t know whether this is possible, but it sounded good.

I’ve also tried changing the file extension from .webloc to .txt. BBEdit and TextEdit will OPEN them now instead of opening the app, but neither app displays anything. This is actually a step backwards because just dropping a .webloc file into an open window in either app would at least display the URL.


I don’t know how to attach a folder action to a hidden folder, but perhaps someone else knows.

I don’t know what to say about the .webloc → .txt change producing no content. It has worked for me in the past and doesn’t now.

Try this with one of your files (my example is for the webloc created when I drag the URL of this forum item to my desktop and then choose it in this script:

set F to open for access (choose file)
set C to read F
close access F
C -->
(* "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"\">
<plist version=\"1.0\">

It wouldn’t be too hard to extract the url from between the tags.