Hi folks,
I generally like to use a single running text file for notes on a specific project I'm working on. I also use Elements and DropBox to synchronize those notes files to my various desktop and mobile devices. Based on scripts written by Jim Harrison and Nicola Vitacolonna I created the script below to automatically create / open a text file in my Elements directory corresponding to the current active OmniFocus project. I'm very much a newbie AppleScript developer so if anyone has tips on how to improve the script do let me know.
-Chris
I generally like to use a single running text file for notes on a specific project I'm working on. I also use Elements and DropBox to synchronize those notes files to my various desktop and mobile devices. Based on scripts written by Jim Harrison and Nicola Vitacolonna I created the script below to automatically create / open a text file in my Elements directory corresponding to the current active OmniFocus project. I'm very much a newbie AppleScript developer so if anyone has tips on how to improve the script do let me know.
-Chris
Code:
--Project Notes with TextMate --Written by Chris Brooks, 2011-09-29 (chris@chrisbrooks.org) --Based on scripts written by Jim Harrison and Nicola Vitacolonna --May be used, edited and redistributed without restriction. --Creates and opens a text file in TextMate corresponding to the selected project set projectsFolderName to "Elements" -- name for projects folder (change this as you like) set projectsDir to (path to home folder as text) & "Dropbox" & ":" set txtPrefix to "" -- change this as you like set txtSuffix to " notes" -- change this as you like --Edit the name and file extension below if you wish to use another application to create and edit the project notes files set txtExtension to ".txt" set txtNoProjectMessage to "To create a project text file, click on or in a project, task or note before running this script" -------------------------------------------------------------------------------------------------------------------------- tell front window of application "OmniFocus" -- get the name of the project containing the current selection try set theTrees to the selected trees of content if the (count of theTrees) is less than 1 then set theTrees to the selected trees of sidebar end if if the (count of theTrees) is less than 1 then display dialog txtNoProjectMessage buttons {"OK"} default button 1 return end if set theSelection to value of item 1 of theTrees if the class of theSelection is folder then set thisProjList to {the name of theSelection} set theGroup to the container of theSelection else set thisProjList to {the name of the containing project of theSelection} set theGroup to the container of the containing project of theSelection end if repeat while the class of theGroup is not document set thisProjList to {the name of theGroup} & thisProjList set theGroup to the container of theGroup end repeat on error display dialog txtNoProjectMessage buttons {"OK"} default button 1 return end try end tell set oldDelimiter to AppleScript's text item delimiters set AppleScript's text item delimiters to " - " set thisProjPath to thisProjList as text set AppleScript's text item delimiters to oldDelimiter set projNotesName to txtPrefix & thisProjPath & txtSuffix & txtExtension set theCurrentPath to projectsDir & projectsFolderName & ":" set theFullFileName to theCurrentPath & projNotesName set newFile to false tell application "Finder" try if not (exists theFullFileName) then set newFile to true end if tell application "TextMate" activate open alias (theFullFileName) if newFile then insert "# " & thisProjPath & " -- " & short date string of (current date) end if end tell on error try open folder (theCurrentPath) on error display dialog "Please create the project folder first, then try again." buttons {"OK"} tell application "OmniFocus" to activate return end try end try end tell