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

 
Scripts to open project folders and notes files Thread Tools Search this Thread Display Modes
Quote:
Originally Posted by RobTrew View Post
What name / location is shown in the prompt if you choose File > Save As from the OO menu ?
The last directory I manually saved an OO file in, no relation to the current project or my home directory.
 
Thanks for these great scripts! I propose a “streamlined” version with an added feature: for each project, a link is created in the Finder that points at the corresponding project in OF.

This modified version of the "Project Folder" script does not ask any questions (by default) and automatically creates an OF link and an OO document for the selected project.

Note that my Projects folder in the Finder resides under a Reference folder in the Documents folder: you may want to change the value of the variable projectsDir to suit your needs. Other customizations are possible: take a look at the properties at the beginning of the scripts.

Code:
--Project Folder
--Written by Jim Harrison, Dec 2008 (jhh.med.virginia.edu).
--Modified by Nicola Vitacolonna, Sep 2009
--May be used, edited and redistributed without restriction.
--Opens folders at a specified location that have the same name as an OmniFocus project that contains the selection
--Edit the name and path below to correspond to the location of the main Projects folder that will contain the individual project folders
set projectsFolderName to "Projects" -- name for projects folder (change this as you like)
set projectsDir to (path to documents folder as text) & "Reference" & ":" -- Path to projects folder (change this as you like)
set askForConfirmation to false -- Set to true if you want the script to ask for confirmation before creating new folders
set linkPrefix to "• [OF] " -- change this as you like
set ooPrefix to "• " -- change this as you like
set ooSuffix 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 ooExtension to ".oo3"
set linksInAllFolders to false -- Set to true if you want an OF link in every folder (not only for projects)
set createOODocument to true -- Set to false if you do not want an OO document to be created for each project
--------------------------------------------------------------------------------------------------------------------------

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 "To open a project folder, click on or in a project, task or note before running this script"
			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
			set theLinkList to {"omnifocus:///folder/" & the id of theSelection}
			set isProjectFolder to false
		else
			set thisProjList to {the name of the containing project of theSelection}
			set theGroup to the container of the containing project of theSelection
			set theLinkList to {"omnifocus:///task/" & the id of the containing project of theSelection}
			set isProjectFolder to true
		end if
		repeat while the class of theGroup is not document
			set thisProjList to {the name of theGroup} & thisProjList
			set theLinkList to {"omnifocus:///folder/" & the id of theGroup} & theLinkList
			set theGroup to the container of theGroup
		end repeat
	on error
		display dialog "Click on or in a project, task or note before running this script." 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

tell application "Finder"
	activate
	try
		open folder (projectsDir & projectsFolderName & ":" & thisProjPath & ":")
	on error
		try
			if not (folder (projectsDir) exists) then
				display dialog "Please create the folder " & projectsDir & " and try again."
				return
			end if
			if askForConfirmation then
				set answer to display dialog "Some folders do not exist yet. Should I create them?" buttons {"Cancel", "OK"} default button 1
				if the button returned of answer is "Cancel" then return
			end if
			
			set theCurrentPath to projectsDir & projectsFolderName & ":"
			if not (folder (theCurrentPath) exists) then
				make new folder at projectsDir with properties {name:projectsFolderName}
			end if
			
			set theParentPath to theCurrentPath
			repeat with i from 1 to (count thisProjList) - 1
				set theFolder to item i of thisProjList
				-- Invariant: at this point theParentPath exists and it is equal to theCurrentPath
				set theCurrentPath to theCurrentPath & theFolder & ":"
				if not (folder (theCurrentPath) exists) then
					make new folder at alias (theParentPath) with properties {name:theFolder}
					if linksInAllFolders then
						make new internet location file to item i of theLinkList at alias (theCurrentPath) with properties {name:linkPrefix & theFolder}
					end if
				end if
				set theParentPath to theCurrentPath
			end repeat
			-- Last folder
			set theFolder to the last item of thisProjList
			set theLink to the last item of theLinkList
			set theCurrentPath to theCurrentPath & theFolder & ":"
			if not (folder (theCurrentPath) exists) then
				make new folder at alias (theParentPath) with properties {name:theFolder}
				if isProjectFolder or linksInAllFolders then
					make new internet location file to theLink at alias (theCurrentPath) with properties {name:linkPrefix & theFolder}
				end if
				if isProjectFolder and createOODocument then
					set projNotesName to ooPrefix & theFolder & ooSuffix & ooExtension
					tell application "OmniOutliner"
						set notesDoc to make new document with properties {name:projNotesName}
						save notesDoc in theCurrentPath & projNotesName
						close notesDoc
					end tell
				end if
			end if
			open folder (theCurrentPath)
		on error
			return
		end try
	end try
end tell
The modified version of the "Project Notes" can be used to open an existing notes document for a project or to create a new one, provided that the project folder already exists (otherwise a warning is displayed). This script also fixes the bug mentioned in previous posts (the new OO document is not the same object as the one saved on disk).

Code:
--Project Notes
--Written by Jim Harrison, Dec 2008 (jhh.med.virginia.edu).
--Modified by Nicola Vitacolonna, Sep 2009
--May be used, edited and redistributed without restriction.
--Opens folders at a specified location that have the same name as an OmniFocus project that contains the selection
--Edit the name and path below to correspond to the location of the main Projects folder that will contain the individual project folders
set projectsFolderName to "Projects" -- name for projects folder (change this as you like)
set projectsDir to (path to documents folder as text) & "Reference" & ":" -- Path to projects folder (change this as you like)
set askForConfirmation to false -- Set to true if you want the script to ask for confirmation before creating new documents
set ooPrefix to "• " -- change this as you like
set ooSuffix 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 ooExtension to ".oo3"
--------------------------------------------------------------------------------------------------------------------------

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 "To open a project folder, click on or in a project, task or note before running this script"
			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 "Click on or in a project, task or note before running this script." 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 ooPrefix & last item of thisProjList & ooSuffix & ooExtension
set theCurrentPath to projectsDir & projectsFolderName & ":" & thisProjPath & ":"
tell application "Finder"
	activate
	try
		open alias (theCurrentPath & projNotesName)
	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
		-- If the folder exists, create an OO document in it
		try
			if askForConfirmation then
				set answer to display dialog "There are no notes in " & theCurrentPath & ". Should I create them?" buttons {"Cancel", "OK"} default button 1
				if the button returned of answer is "Cancel" then return
			end if
			tell application "OmniOutliner"
				activate
				set notesDoc to make new document with properties {name:projNotesName}
				save notesDoc in theCurrentPath & projNotesName
				-- BUG: the saved document does not seem to be the same object as the new document
				-- We overcome this problem by closing and re-opening the document
				-- See also http://forums.omnigroup.com/showthread.php?t=8356
				close notesDoc
				open theCurrentPath & projNotesName
			end tell
		on error
			tell application "OmniFocus" to activate
			return
		end try
	end try
end tell
 
I am not familiar with Applescript but would like to change the path of these Project folders so that they're found in my dropbox folder and not my document folder. I can not figure out how to alter this so that it works:

set projectsPath to (path to documents folder as text) -- path to main projects folder

Everything I try comes up with some sort of error.

Advice, please? Thanks.
 
Quote:
Originally Posted by RandyShulman View Post
I am not familiar with Applescript but would like to change the path of these Project folders so that they're found in my dropbox folder and not my document folder. I can not figure out how to alter this so that it works:

set projectsPath to (path to documents folder as text) -- path to main projects folder
Try this:

Code:
set projectsDir to (path to home folder as text) & "Dropbox" & ":" -- Path to projects folder (change this as you like)
 
Quote:
Originally Posted by whpalmer4 View Post
Try this:

Code:
set projectsDir to (path to home folder as text) & "Dropbox" & ":" -- Path to projects folder (change this as you like)
Thanks for the suggestion. It's kind of working. But when I go to save the file, it strips it of its icon and reduces the file size considerably. Then it just hangs when I try to run it in the program. Again, I'm a novice at this, so are there additional steps to take? Much appreciated.
 
Hi,

I don't use omnioutliner - could somebody advise me what lines of code to remove to get round this please or what code would I use to open a Word Doc?

Thanks for a great script.
Cheers


Nick

Last edited by nickwild; 2010-01-24 at 01:43 AM..
 
Quote:
Originally Posted by nickwild View Post
Hi,

I don't use omnioutliner - could somebody advise me what lines of code to remove to get round this

Nick
Hi,
for me it was sufficient to take out the following lines:

Code:
				if isProjectFolder and createOODocument then
					set projNotesName to ooPrefix & theFolder & ooSuffix & ooExtension
					tell application "OmniOutliner"
						set notesDoc to make new document with properties {name:projNotesName}
						save notesDoc in theCurrentPath & projNotesName
						close notesDoc
					end tell
				end if
It's not a clean solution, since there are now unused variables, but it should help. I also set createOODocument to false.

Good Luck.. ;)
 
Hi,

for me the script was only creating the first of the selected folders/projectlists.

I would like to create the whole tree-structure as folders. I played a little bit with the code, but I am new to Applescript. I guess one would need to create an array and read out the other items of the selection and then run a loop on the finder part.

Before I spend a weekend on this, I was woundering, if not someone else allready solved the problem: How do I create a comlete structure of folders like the project tree at once. I can't be the first.. not?

Cheers,
m.
 
Does anyone have an archive of the source files? It appears that the link given earlier is no longer valid.

Thanks!
Rutilate
 
mathiasm, did you ever create the script to create all folders at once?
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How best to organise files and folders? philrob Omni Lounge 4 2012-06-25 05:21 PM
Will OmniPlan for iPad open Microsoft Project files? amarsh OmniPlan for iPad 2 2012-06-07 10:41 AM
Open Folder / Notes Scripts broken in Lion Full Screen Mode nunez OmniFocus 1 for Mac 3 2011-10-06 02:42 PM
Slow to Open OF and Open the Settings [fixed by reducing zip files] GreenLorax OmniFocus for iPhone 26 2009-07-26 01:38 PM
Scripts that add simple tags to the end of notes... a11en OmniFocus Extras 9 2008-08-29 08:50 PM


All times are GMT -8. The time now is 11:02 PM.


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