Applescript - export Omnifocus tasks to Obsidian checklist (or kanban)

update

This script has been overhauled by DrJJWMac over at the MPU forums see here :

:warning: warning, this script will choke on tasks with more than one paragraph, or special characters like slashes

original post

This script

  • creates a new .md in Vault using project title from Omnifocus
  • appends task’s title as a checklist item to that .md
  • IF the Task in Omnifocus has a note (text only)
    • encloses the added task in [[]] wiki brackets

    • creates separate .md with name of task

    • adds Omni note text to that .md in ObsidianTo convert into kanban use this plugin GitHub - mgmeyers/obsidian-kanban: Create markdown-backed Kanban boards in Obsidian. , and just “Insert template” above the checklist.

      tell application "OmniFocus"
          tell front window
      	    set my_trees to selected trees of content
      
      ## INSERT YOUR OBSIDIAN VAULT PATH HERE
      
      tell application "Finder" to open ("/Users/XXXX/DT Documents/Vault/" as POSIX file)
      
      repeat with i from 1 to count of my_trees
      	set my_selection to value of item i of my_trees
      	set task_name to name of my_selection
      	set task_note to note of my_selection
      	set project_id to containing project of my_selection
      	set project_name to name of project_id
      	
      	
      	try
      		tell application "Finder" to set theLocation to (folder of the front window as alias)
      	end try
      	
      	if task_note is not "" then tell application "TextEdit"
      		
      		## INSERT YOUR OBSIDIAN VAULT PATH HERE
      		
      		set n to "/Users/XXXX/DT Documents/Vault/" & task_name & ".md"
      		close access (open for access n)
      		write task_note to n as "utf8" starting at eof
      		write " 
      " to n as "utf8" starting at eof
      		end tell
      	
      	tell application "TextEdit"
      		
      		## INSERT YOUR OBSIDIAN VAULT PATH HERE
      		
      		set f to "/Users/XXXX/DT Documents/Vault/" & project_name & ".md"
      		close access (open for access f)
      		
      		
      		if task_note is not "" then set task_name to "[[" & task_name & "]]"
      		
      		
      		write "- [ ] " & task_name & " " to f as "utf8" starting at eof
      		write " 
      " to f as "utf8" starting at eof
      		
      	end tell
      	
      	
      end repeat
      
      end tell
      
      
      
      end tell

I tried the script but I get errors:

tell application “TextEdit”
open for access “/Users/mikeormerod/vault/PreSales.md”
error number -10004

Any thoughts?

Mmmm, I’m no expert at this stuff but did you add that “open for access”? It’s not in my script originally, is it?

This script has been overhauled by DrJJWMac over at the MPU forums see here :

2 Likes

This is great and worked first time, Thanks.