The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Script to create a project notes text file (http://forums.omnigroup.com/showthread.php?t=22252)

brookscl 2011-09-29 07:35 AM

Script to create a project notes text file
 
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[/CODE]

steve 2011-10-03 03:50 PM

This is a very clever idea. For what it is worth, it didn't run on my machine. I got, "The variable txtPrefix is not defined."

Steve

brookscl 2011-10-26 07:03 AM

[QUOTE=steve;102424]This is a very clever idea. For what it is worth, it didn't run on my machine. I got, "The variable txtPrefix is not defined."

Steve[/QUOTE]

Sorry Steve - just got back to the forums and should have been checking earlier. Make sure you paste all of the text from the top - txtPrefix is defined up there. Let me know if you continue having this problem.

N.B - should have posted thread this under "Omnifocus Extras" - apologies.


All times are GMT -8. The time now is 07:48 AM.

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