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

 
Acting on all projects using Applescript Thread Tools Search this Thread Display Modes
Very nice robtrew. I've seen that sort or "where" syntax in Applescripts before. I'll give that a try for my counts script over the next few days.

I also noticed the "tell application id" - I've been wondering about the best way to address the non-default document for my "maybe someday.ofocus" workflow. I'm going to give "tell document id "<doc id>" a try.


robtrew and curt (et al.), I've gathered some decent references on applescript an am going to try to make the time to do some foundational learning about it. I'm always trying to shoehorn these things into my schedule and have hesitated learning Applescript properly, i.e. "I just want to learn enough to get this done." Time I did this right. If you know of good references, or can suggest the quintessential reference, by all means please do...

Cheers, have a great weekend!
 
I dabbled for a long time, then learned from Matt Neuburg's excellent book. If I was starting again today, I'd probably use AppleScript 1-2-3 by Sal Soghoian.
__________________
Cheers,

Curt
 
Nice, Rob, thanks. Do you see an easy way to use the where-queries and still factor out the filtering into a separate handler? I guess one could retrieve the list, filter it, then process it. I'll have to play with the timing on that.
__________________
Cheers,

Curt
 
Quote:
Originally Posted by curt.clifton View Post
I guess one could retrieve the list, filter it, then process it
If one wants to make use of where queries, (to improve performance, for example) retrieval and filtering have to be combined.
(The where clause is part of get syntax, and can't be applied to lists - hence the scope for an efficient implementation).

Quote:
Originally Posted by curt.clifton View Post
Do you see an easy way to use the where-queries and still factor out the filtering into a separate handler?
You might find a meta-programming route to passing variable arguments to where clauses. (I can't spot a simple one at the moment - run script gets messy if you try to circumvent its overheads - See Matt Neuburg's section on the Run Handler).

Short of this, and given the need to combine filtering with retrieval, the main room for flexibility probably lies in branching, at some level, between multiple retrieval options, each with an alternative hand-coded where clause.

A trade-off, as always, between flexibility and performance, but a useful rule of thumb is to exercise parsimony and discretion wherever possible in the implicit or explicit use of get, by adding a where condition or two - it can make code simpler, as well as faster.

--

Last edited by RobTrew; 2010-02-13 at 04:35 AM..
 
Thanks for the interesting food for thought, Rob.

As a programming languages geek, I like to push on the different features of a language to see how far I can take them. I tend to write Applescript as if it's Scheme with fewer parentheses and no call-cc. It's good to be reminded that AS is much faster if the native app is doing the filtering in a single event.
__________________
Cheers,

Curt
 
Quote:
Originally Posted by curt.clifton View Post
It's good to be reminded that AS is much faster if the native app is doing the filtering in a single event.
If no filtering is needed, the project list can, of course, be flattened even more simply:

Code:
tell application id "com.omnigroup.OmniFocus"
	set lstAllProjects to my ProjectList(front document)
end tell

on ProjectList(oParent)
	using terms from application "OmniFocus"
		tell oParent
			set lstFolders to folders -- where etc
			set lstProjects to projects -- where etc
			if lstFolders ≠ {} then
				lstProjects & my FolderProjects(lstFolders)
			else
				lstProjects
			end if
		end tell
	end using terms from
end ProjectList

on FolderProjects(lstFolder)
	set lstProject to {}
	repeat with oFolder in lstFolder
		set lstProject to lstProject & ProjectList(oFolder)
	end repeat
end FolderProjects

Last edited by RobTrew; 2010-02-22 at 07:03 AM..
 
PS an even shorter (and non-recursive) route to a full project list would be:

Code:
set lstProjects to ProjectList("all-projects")

on ProjectList(strFilter)
	tell application id "com.omnigroup.OmniFocus"
		tell front window
			set selected view mode identifier to "project"
			set focus to {}
			tell sidebar
				select library
				set selected smart group identifier to strFilter
			end tell
			set lstProject to {}
			repeat with oTree in trees of content
				set end of lstProject to value of oTree
			end repeat
			lstProject
		end tell
	end tell
end ProjectList
Which can be simply filtered by choosing an alternative smart group identifier string :

"remaining-projects"
"active-projects"
"stalled-projects"
"pending-projects"
"on-hold-projects"
"dropped-projects"
"completed-projects"
--

Last edited by RobTrew; 2010-02-28 at 02:27 PM..
 
Rob,

That doesn't filter out folders.
__________________
Cheers,

Curt
 
Quote:
Originally Posted by curt.clifton View Post
That doesn't filter out folders.
It doesn't allow us to query directly on folder properties, but it does give us a flattened and folder-free list of all the projects in the database very easily and flexibly ...

I think it works quite well as a quick response to Fudster's original problem:

I've been having an awful time trying to obtain all the projects in my omnifocus document in Applescript.

Generally, it seems a good idea not to lose sight of OF's built-in querying when drafting scripts - any flat list that can be automatically queried into existence in the content panel can be readily harvested through applescript ...

(and of course, we can save and restore states if we want to avoid GUI side-effects ...)

--

Last edited by RobTrew; 2010-03-01 at 02:58 AM..
 
It does not give a folder-free list of all the projects. When I run your script it includes every folder and every project. As you say, it is flattened. You could, of course, filter in the loop to eliminate the folders. I wonder if the difference between what we're seeing has to do with view bar settings that your latest iteration isn't changing.
__________________
Cheers,

Curt
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript for dependent projects fudster OmniFocus Extras 10 2011-03-17 03:00 PM
Can't Get Through Initial 1st Sync & Now OF is Acting Odd. HappyDude Other WebDAV 4 2009-09-06 03:06 PM
.Mac and file saves acting weird since Leopard... dude OmniOutliner 3 for Mac 0 2008-03-05 09:30 AM
Can Omniplan do this? 10,000 projects / AppleScript isv OmniPlan General 3 2007-07-04 03:00 AM
AppleScript Gurus: Projects -> Notes BwanaZulia OmniFocus 1 for Mac 6 2007-06-21 11:02 AM


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


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