AppleScript Devonthink Tasks in Markdown File to Omnifocus

The type of prompting I am suggesting is not used to train AI or benefit other users - at least not with a paid AI acount. Particularly used in combination with a tool such as Cursor (as we dicussed before), it would be a tool to make your own coding more efficient.

Spreadsheets, spell-checkers, and grammar checkers once experienced pushback similar to yours against AI; they have now become mainstream.

Moreover you could turn lemons into lemonade. You could fairly easily create a custom GPT or AI agent which authors quality JXA scripting code - then sell subscriptions to it. You are probably more qualified than anyone in the universe to do that.

This is an interesting script! I often have makeshift to do lists in a DT document that I want to move to Things. Ah, too bad Things doesn’t allow AppleScript to create checklists within a To Do yet!

1 Like

Their AppleScript is quite limited. Many task managers offer very little in the way of robust inter-application communication, especially when many are essentially front ends to web services or Electron apps.

I just happened to download Things since I knew I could just install and do a quick proof-of-concept with it.

They do use Markdown in their notes, and if you do an MD checklist (“- ”) it will let you check/uncheck it with a key command (command-K). Not as clean as their official checklist option, but I may play with it to copy/paste items that have subitems.

My impression is they stopped developing the AppleScript capability a long time ago but keep it around as a legacy option. Their AppleScript guide was last updated 2018-10-10. So I wouldn’t get my hopes up…

Instead they focused their efforts on Shortcuts, which they point towards at the top of your link. And that does give the capability of adding checklists. To-do items have a Checklist property which can be manipulated with the Edit Items action. The overall options actually seem pretty extensive at this point.

I think you can also access all of the Shortcuts functionality with the things:/// URL scheme. Possibly more, even. Depending on how you feel about Shortcuts, you might prefer working with that.

Maybe this…?

I don’t use Things either so I don’t know what would be expected.

tell application id "DNtp"
	if (selected records) is {} then return
	
	repeat with theRecord in (selected records)
		if (record type of theRecord is markdown) then
			set recordName to (name without extension of theRecord)
			set src to (plain text of theRecord)
			set recordID to (reference URL of theRecord)
			set od to AppleScript's text item delimiters
			set theTasks to {}
			repeat with theParagraph in (paragraphs of src)
				if theParagraph contains "[ ]" then
					set AppleScript's text item delimiters to "[ ] "
					set theTask to text item -1 of (text items of theParagraph)
					if theTask is not "" then copy ("- [ ] " & theTask & linefeed as string) to end of theTasks
				end if
			end repeat
			set AppleScript's text item delimiters to od
			if theTasks is not {} then
				my processtasks(recordName, theTasks)
			else
				log message "No tasks were found in this document." record theRecord
			end if
		end if
	end repeat
end tell

on processtasks(recordName, theTasks)
	tell application "Things3"
		make new to do with properties {name:recordName, notes:(theTasks as string)}
	end tell
end processtasks

Exactly, thanks! Things is pretty smart about it’s markdown, so you can even copy that note and paste it into the checklist option, and it knows to convert it correctly.

I haven’t used Shortcuts a ton because I much prefer coding by text than flowchart ;-). But Cultured Code seems to have documented it well enough so maybe it’ll work easily enough. I’ll have to give it a try.