Scripting or KM to Get the UUID for a Newly Created Draft in Mac OS?

Inspired by @MacSparky 's contextual computing discussion about creating interlinking between task manager, files, and project information, I’ve been working on a Keyboard Maestro macro to run when I set up a new project. The goal for the macro is to take the project name as input and then: 1) set up a new project in OmniFocus in the appropriate project folder; 2) create a folder for the project in my Active Projects folder via Finder; and 3) create a Drafts note for the project. I want to have URL links to each of the other components in both the Omnifocus record and the Drafts note.

So, I’ve got this 99% complete – I can create all three needed components, I can generate a workable file URL and a link to the Omnifocus project, and I can use AppleScript to create a new draft with the project name and the URLs to both the Omnifocus project and the project folder. What I can’t figure out, though, is how Ito automate obtaining the URL (or UUID, from which I can create a URL) for the new draft so that it can also be included in the Omnifocus Project note.

Has anyone figured out how to automate cracking this last piece of the puzzle? I’m so tantalizingly close to having this process completely automated that I don’t want to have to manually do this last piece…

And, of course, once complete I will post the KM macro that I’ve created for anyone else who wants to live the @MacSparky project lifestyle!

1 Like

I hope you get a good answer. I pretty much gave up on a number of Shortcuts automations, because I couldn’t figure out how to do this.

I hope you get a good answer. I pretty much gave up on a number of Shortcuts automations, because I couldn’t figure out how to do this. Watching!

How are you creating the new Draft?

Chances are that you will be receiving the UUID in the response from Drafts. I think it does it for every way it creates a new draft, but there are exceptions - e.g. using a URL scheme call but not utilising x-callback-url.

Alternatively, it is possible to retrieve the UUID directly from the Drafts database for the most recently created draft.

1 Like

I used the very basic AppleScript syntax that as been added. I’m open to other ways of creating the draft if they can net me the UUID. This is the script I currently have:

The DraftContent variable contains a text block that has the project name, the OmniFocus link, and the project folder link. The projects flag has the draft show up in a Workspace that contains the Drafts for currently active projects.

@sylumer – you mentioned that Drafts returns the UUID on creation of a new draft. Is there a way to then script to get that UUID?

No need to change the method. AppleScript is one of the methods that can return the UUID, and is doing so in your macro. Here’s an example macro showing a way of getting it.

https://share.thoughtasylum.com/share/keyboardmaestro/create_draft.kmmacros

1 Like

THANK YOU @sylumer! That solved the problem and I’m now 100% automated.

Check the solution @sylumer provided below – it gave me exactly what I needed. I need to clean up my script a little and add some documentation and then I’ll post what I’ve done.