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

 
Use Applescript to focus on a folder Thread Tools Search this Thread Display Modes
I'd like to write an Applescript to allow me to create a shortcut to focus on a particular folder which is hardwired into the script. This would allow me drill down to a single area of responsibility.

I have been doing this with perspectives but would like to be able remain in my current view and just filter out the tasks from folders that I don't want visible. When I use Perspectives to accomplish this, the perspective imposes either the Project or Context view mode.

I thought this would be a pretty trivial task so I fired up AppleScript Editor opened the OmniFocus Library and I have completely struck out.

To make it nice and visual, I have created these three icons that I would like to click, invoke an AppleScript and focus on my chosen area of responsibility.



Any help would be appreciated.
 
Quote:
Originally Posted by Tukanuk View Post
I'd like to write an Applescript to allow me to create a shortcut to focus on a particular folder which is hardwired into the script.
It would be helpful if the Complete function (which quickly finds projects and contexts by name) supported folders as well, but this draft (which searches recursively for the named folder) may be in the region of what you need.

(The first line needs to be edited to specify the name of a folder)

Code:
property pstrFolderName : "EDIT THIS STRING TO NAME OF A FOLDER"
property pstrTitle : "Focus on folder"

tell application "OmniFocus"
	set oDoc to default document
	
	set oFolder to my FolderByName(oDoc, pstrFolderName)
	if oFolder is not missing value then
		set focus of front document window of oDoc to {oFolder}
	else
		display dialog "Folder name: " & ¬
			pstrFolderName & return & "not found" with title pstrTitle
	end if
end tell


on FolderByName(oParent, strName)
	using terms from application "OmniFocus"
		set lstMatches to folders of oParent where name is strName
		if length of lstMatches > 0 then
			return first item of lstMatches
		else
			set lstFolders to folders of oParent
			repeat with oFolder in lstFolders
				set varResult to FolderByName(oFolder, strName)
				if varResult is not missing value then return varResult
			end repeat
		end if
		return missing value
	end using terms from
end FolderByName
--

Last edited by RobTrew; 2010-05-31 at 04:19 PM..
 
Perfect. That works exactly how I want it to. Thanks!
 
Quote:
Originally Posted by Tukanuk View Post
Perfect. That works exactly how I want it to. Thanks!
Of course the simplest and swiftest version of such an applescript would just look something like this:

Code:
property pstrFolderID : "EDIT THIS STRING TO AN ID"
-- e.g. property pstrFolderID: "oqoRnkE5jp1" -- Pro bono folder

tell application "OmniFocus"
	set oFolder to folder id pstrFolderID of default document
	set focus of front window to {oFolder}
end tell
But then you would have to know the unique ID of the folder. (A minor advantage being that this ID doesn't change if you later adjust the name of the folder)

You could grab the ID of the selected folder (putting it in the clipboard) with a snippet like this:

Code:
property pTitle : "Get id of selected OF object"

tell application id "com.omnigroup.OmniFocus"
	tell front window
		set lstSelected to value of (selected trees of content)
		if length of lstSelected < 1 then
			set lstSelected to value of (selected trees of sidebar)
		end if
	end tell
	if (count of lstSelected) > 0 then
		tell first item of lstSelected
			try
				set {strID, strName, strClass} to {id, name, class as string}
			on error
				display dialog "Select a folder, project, or task" with title pTitle
				return
			end try
		end tell
		tell application id "com.apple.finder"
			set the clipboard to strID
		end tell
		display dialog strClass & " name: " & strName & return & return ¬
			& strClass & " id: " & strID & return & return ¬
			& "( " & strID & "  placed in clipboard )" with title pTitle
	else
		display dialog "Select an object in OmniFocus and try again" with title pTitle
	end if
end tell
--

Last edited by RobTrew; 2010-05-31 at 05:41 PM..
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
AppleScript to create a Project inside a folder? RicardoSaporta OmniFocus 1 for Mac 10 2012-04-03 07:35 AM
AppleScript to open bookmark folder in Safari urtlnomis OmniFocus Extras 0 2011-04-05 09:12 AM
Round trip local folder sync with Applescript and Folder Actions mf.studio OmniFocus Extras 0 2009-09-20 10:42 AM
Where is my database saved? [A: the OmniFocus folder inside App Support folder] Michael Blake OmniFocus 1 for Mac 2 2009-08-10 02:08 PM
Applescript OmniFocus to focus on one project Lutin OmniFocus Extras 4 2007-09-20 02:52 AM


All times are GMT -8. The time now is 03:04 AM.


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