The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Script to create a project notes text file Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
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


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
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting project + context via script (modifying a DEVONthink script) bernd OmniFocus Extras 2 2012-09-08 12:10 PM
Script to create Stencil lsamberg OmniGraffle General 0 2010-08-31 05:13 AM
Project Notes text and attachments BruceG OmniFocus for iPhone 5 2009-11-05 11:05 AM
Open or Create Project Folder Script ptone OmniFocus Extras 0 2008-08-11 11:17 AM
text won't create new text line alassiter OmniGraffle General 1 2007-12-18 12:12 PM


All times are GMT -8. The time now is 05:15 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.