URL to file from applescript


I understand that I can construct the URL to a record by hand by saying

set xurl to "x-devonthink-item://" & (get uuid of curRecord)

ie by getting the uuid and appending the x-devonthink part by hand. I have two questions:

  1. is there some way to get it automatically (ie without having to prepend “x-devonthink-item://” by hand?
  2. If I use “edit->copy item link” to get the url, I get a URL that, whe pasted in eg omnifocus, displays the name of the record instead of the whole URL. That is, just like URLs in HTML. How could I achieve this in applescript? Now I don’t actually know anything about HTML or indeed what these x-url business really means, so if anybody could also point me to some good explanation of it I’d appreciate it.


To answer your question number 2 first, the reason you get a label in Omnifocus is because the RTF support in OSX will convert the xurl to this:

{\field{*\fldinst{HYPERLINK “x-devonthink-item://35D3C10A-BB15-4228-86B7-A08E5A9CC81E”}}{\fldrslt
\f0\fs24 \cf0 metadata-test.rtf}}}

It’s a feature of the operating system and not anything that DTPO or Omnifocus does.

As for your question number 1, DTPO doesn’t store a “pre-made” copy of the xurl, so you have to concatenate the string “by hand” (you’re not really typing it are you?)

Perhaps if you said more about what you are trying to do, someone could be of help.

Best, Charles


Thanks. I wrote a longer reply but apparently the forum software logged me out before submitting it, so that it asked me to login again before submitting and lost my edits… So I’ll try to put my question succinctly.

I have in my script the two lines

set xurl to "x-devonthink-item://" & (get uuid of curRecord)
set recordName to name of curRecord

and wish to end up with a link in an omnifocus (in this case) rtf field which has the form that you said, ie, something along the lines of
{\field{*\fldinst{HYPERLINK “x-devonthink-item://35D3C10A-BB15-4228-86B7-A08E5A9CC81E”}}{\fldrslt
\f0\fs24 \cf0 metadata-test.rtf}}}

How do I do that (in applescript)? If I just add the xurl thing in a note, it gets recognized as a link. But I want it to be displayed like you describe, and I don’t know how to do it.


I assume you want to do this programmatically, and can’t simply cut ‘n’ paste the link from DTPO?

I don’t have OmniFocus, but I try it in one of two ways:

  1. Use a Quickeys-type program or UI Applescripting to record the cut ‘n’ paste menu sequence, then call the sequence in your Applescript.

  2. Cut ‘n’ paste a DTPO link into OmniFocus and look at the resulting OF file as plain text (not RTF). Find your pasted link and copy the surrounding formatting similar to what I posted. Concatenate that on both sides of the DTPO UUID instead of the “x-devonthinkitem://” text you currently are using. Then use that object in your script.

HTH, Charles

Unfortunately I’d need to do this in a script, so can’t use utilities. GUI scripting would work, but then I’d have to do the whole thing using GUI scripting (or once it’s on the clipboard I could continue with normal scripting, I guess). So that would work, but I’d rather I worked out how to insert such a link via scripting (anyway I get annoyed by not knowing things so it’s not just practical).

But that’s not going to work: it’s XML. The respresentation on disk doesn’t have to be simply related to the representation in memory, which doesn’t have to be simply related to the representation in applescript etc… And pasting in the RTF form of a file containing such a link produced by DT, ie, something along the lines of

{\fonttbl\f0\fnil\fcharset0 HoeflerText-Regular;}
{\field{\*\fldinst{HYPERLINK "x-devonthink-item://1FBDE4B3-FDF4-40B1-8470-E4F135452074"}}{\fldrslt 
\f0\fs28 \cf2 \ul \ulc2 stopping NDSolve on a condition}}}

also doesn’t work (and neither do subsets of this). I am guessing that this can be done and I just don’t know how to, though. Probably because I don’t really know applescript.

Anyway, thanks for the suggestions.


PS: I was again asked to login after I wrote this reply, and, when I did, lost all the stuff that I had typed! Of course this time I had copied it… Is it something I am doing wrong? I am on Safari 4.

Just to deal with your posting problems: Select the “Keep me logged on permanently” option.

Perhaps I can post a simple example solution for your problem…


Well, if you find the solution, please do post it. At the moment I am at a bit of a loss: if I do “Copy Item Link” by hand (from the menu) and then run

tell application "System Events" to set clpBrd to the clipboard

then clpBrd contains simply the text of the url, eg
and nothing else. And yet if I paste the same thing into OmniFocus (say), I get a link to this url but under the name of the record (ie, the clickable link is called “stopintegrationoncondition”, as the actual record in my DT database is snappily titled).

Or if I look at the clipboard that LaunchBar displays, it shows the record’s name, an icon indicating it’s a URL and the name of the application whence it came (“DEVONThink Pro Office”). It doesn’t explicitly show the URL itself. But that is the only thing applescript sees, apparently.

Yes, that’s pretty much what I described above. The DTPO side is the easy part. I spent some time looking at OmniOutliner yesterday, and was surprised I couldn’t locate where the link was stored as an Applescript object. Not a criticism of Omni’s Applescript excellent implementation, it’s just complicated.

I know you’re using OmniFocus, but I have to believe the foundation is the same.

If you look at the resulting file, it seems to be saved as a simple HREF, and so should be pretty easy to script (ie no fiddling with RTF) once you have a reference.

I thought I’d post on the Omni forum, unless someone here already knows how to do this?

Best, Charles

I am getting confused by your posts. What does this have to do with omnifocus’ applescript implementation? It happens with many applications, not just Omni ones. As I explained above, I do not see a way to get anything but a text version of the URL from the clipboard contents, while OF and various other applications can get more information.

Well, I could just get the name and link from DT and literally insert it into an omnifocus file by hand, but that seems like overkill to me. And anyway I still do not understand why I cannot get anything except the URL itself from the clipboard via applescript, even though lots of programs can apparently get the name of the record too.

Maybe I’ll try that, and maybe I should also try asking this question on an applescript list.

Anyway thanks.


No. But it’s only one line of code so I don’t think that this requires any enhancements :wink:

DEVONthink is copying the URL and its name to the clipboard. Some applications (e.g. DEVONapps, the Finder, TextEdit or Safari) use this, some not (e.g. Mellel or Pages). But I don’t think that this is possible via AppleScript.

Right, mostly I asked because I was curious. I can’t imagine that it’ll save anybody more time than it will take to implement.

Yes, I can’t find any way to do it. Oh well.

Thanks to both for the replies.

Here’s a useful thread from the Omni Forum that demonstrates how to make a link from the filename and the URL:


So this should be pretty straightforward in OmniFocus.

Sadly, it’s not as helpful to me with OO3…

Best, Charles

Thanks, that does solve the problem of creating such a link in omnifocus.

OmniOutliner doesn’t yet have the support that OmniFocus does, but this whole thing is pretty easy-- anywhere actually.

Currently I’m grabbing the UUID in DTPO2 and storing it in a OO3 cell. I have an Applescript that concatenates “x-devonthink-item://” as a prefix and then I say:

open location "x-devonthink-item://634B2F90-3E61-48BB-8188-83B240F70A3A"

```...or whatever your UUID, and the correct document opens. Couldn't be simpler! (as usual with DTPO2)

Enjoy, Charles

Of course! This is what I stated in my first post, where the snippet

set xurl to "x-devonthink-item://" & (get uuid of curRecord)


The problem is to have a URL displayed as, not “x-devonthink-item://foo”, but something user-defined (eg the name of the record, for example). This problem is solved by Ken Case’s script in the forum you linked to.

For example, try selecting something in DT and then “Copy Item Link”. Then paste that into OmniOutliner. Do you see what the difference is?

OK, Smartypants. Remind me to be less helpful in the future…

?? Well, I’m sorry it came across that way, but I have to admit that even rereading my post I can’t see anything that could be taken that way. I guess the impersonality of a purely written medium can easily lead to misunderstandings.

Anyway, I certainly did not intend to insult anyone, especially one who went to the trouble to solve my problem for me!