I’m writing an applescript that takes a webloc file as input. I need it to extract the the url from inside of a .webloc file and assign it to a variable so I can use it input to a command line program. Is there an existing applescript I can steal from that does this? I know there is a “copy item link” function in the Edit dropdown menu in Devonthink.
A .webloc is barely a file, it’s just a bookmark – Title and URL… Actually, when I open it in a text editor, I see a small .plist XML document of 8 lines. Never tried before.
As a database record it can of course have additional metadata.
Do you know AppleScript? I almost assume you don’t – otherwise, wouldn’t your first course of action be to open DEVONthink’s scripting dictionary and search for “URL”?
I have only poked a little at it, and that’s what I would do. Looks like every database record has a property called URL. Have you looked at some of the scripts included with DEVONthink? Anything related to downloading could offer clues.
For example, the Smart Rule Script Add Linked Images to Download Manager includes this line:
set theURL to URL of theRecord
Since I don’t actually know AppleScript, I can’t help more than that, and wasn’t sure if I should reply. But maybe it helps point you in the right direction.
@troejgaard is on the correct track. There’s no need to parse the XML. An imported bookmark has its URL recorded. A simple example with a selected record would be…
tell application id "DNtp"
set theURL to (URL of (selected record 1))
end tell
Do note, more than just boomarks can contain URLs, e.g., a PDF downloaded from online. So you’d have to do some error-trapping or filter things, e.g., in a smart rule if you want to only process bookmarks.
I know there is a “copy item link” function in the Edit dropdown menu in Devonthink.
This is not the item’s URL. That is a unique link to the specific item in your database.
Modern .webloc files are indeed just .plist files internally but older ones used only the resource fork. But I can’t remember which version of OS X changed this.
Anyway, System Events scripting supports property lists: