The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Applescript to count database items (http://forums.omnigroup.com/showthread.php?t=10860)

Frank M 2008-12-16 04:31 AM

Applescript to count database items
 
Is there some built in function or a script somewhere that will tell me how many tasks that I have?

Or, not being an AppleScripter myself, perhaps someone could point me to a pre-written script that would count my tasks in total, complete, to do, per context, per project, per due date, etc?

It may sound odd, but there's a certain motivation and satisfaction seeing the numbers go down day per day.

Thanks for letting me know.

refulgentis 2008-12-16 09:35 AM

[url]http://forums.omnigroup.com/showthread.php?t=9983[/url] will count all items you have selected in your current view

Toadling 2008-12-16 11:36 AM

2 Attachment(s)
It's not very sophisticated and may not provide everything you're looking for, but here's a quick script I wrote a couple months ago and posted in a different thread on this forum. I've made a few changes since then, so rather than link to that old post, here's the updated script.

[ATTACH]819[/ATTACH]

If you have a large database, it may take a few seconds to collect the data. The script output looks like this:

[ATTACH]820[/ATTACH]

Hope this helps.

-Dennis

Frank M 2008-12-16 03:54 PM

[QUOTE=Toadling;52523]It's not very sophisticated and may not provide everything you're looking for, but here's a quick script I wrote a couple months ago and posted in a different thread on this forum. I've made a few changes since then, so rather than link to that old post, here's the updated script.

[ATTACH]819[/ATTACH]

Hope this helps.

-Dennis[/QUOTE]

It sure does, thanks! And by the way, it's also a nice re-intro to apple script (we can actually declare globals and such now? Cool!)

Thanks to both of you!

rsailer@mac.com 2008-12-26 10:01 AM

Script
 
Neat script! Thanks for putting it together. Any chance you could get some granularity on actions (ie next actions, available actions, completed actions)?

Thanks,

Randy




[QUOTE=Toadling;52523]It's not very sophisticated and may not provide everything you're looking for, but here's a quick script I wrote a couple months ago and posted in a different thread on this forum. I've made a few changes since then, so rather than link to that old post, here's the updated script.

[ATTACH]819[/ATTACH]

If you have a large database, it may take a few seconds to collect the data. The script output looks like this:

[ATTACH]820[/ATTACH]

Hope this helps.

-Dennis[/QUOTE]

whpalmer4 2008-12-26 03:13 PM

[QUOTE]Neat script! Thanks for putting it together. Any chance you could ...[/QUOTE]

Remember, Dennis, no good deed goes unpunished :-)

mseibert 2008-12-27 04:33 AM

Thanks for this script. That helped already. :-)

[QUOTE=Toadling;52523]It's not very sophisticated and may not provide everything you're looking for, but here's a quick script I wrote a couple months ago and posted in a different thread on this forum. I've made a few changes since then, so rather than link to that old post, here's the updated script.

[ATTACH]819[/ATTACH]

If you have a large database, it may take a few seconds to collect the data. The script output looks like this:

[ATTACH]820[/ATTACH]

Hope this helps.

-Dennis[/QUOTE]

BwanaZulia 2011-01-12 05:26 AM

2 Attachment(s)
Just a small update to the Count Database Items script. Paul (from OmniGroup) and I added support for Pending projects (projects that are active but are pending) and Current Projects which is active projects minus pending projects.

This really helps me see how much I have on my plate and I have built it into my weekly review to make sure I am under a certain amount.

BZ

RobTrew 2011-01-12 07:10 AM

Nice work. A couple of thoughts:

Your total action count is probably not quite right - you are taking the total number of records in the task table, but a significant proportion of these records are actually projects rather than tasks.
(Of those that remain, some are actions and some are action groups. For some purposes it may be helpful to count these separately).

(For an approach which separately counts actions, action groups, and inbox actions, see, for example: [URL="http://forums.omnigroup.com/showthread.php?t=18405"]Script for a Quick listing of OmniFocus Statistics[/URL]

Your useful addition of a [I]Pending[/I] statistic may also need adjusting to take account of folder status. OmniFocus does not treat projects as [I]pending[/I] if their folder (or any ancestral folder) is dropped.

Your whose clause could therefore be expanded to something like:[INDENT][I]((singleton action holder is false) and (status is active) and (start date > now) and ((effectively hidden of its folder is false) or (its folder is missing value)))[/I][/INDENT]
(See [URL="http://forums.omnigroup.com/showthread.php?p=84886#post84886"]Draft FAQ: OF 1.8 Filter options and their search-language equivalents[/URL])

Finally, a small programming point which might allow some simplification and a slight gain in speed - as of Ver 1.8 we no longer need to recursively walk the object trees - you can get your stats directly by applying the where/whose conditions directly to collections such as [I]flattened folders[/I], or [I]flattened projects[/I] of the default document.

Rob

[COLOR="White"]--[/COLOR]

RobTrew 2011-01-12 09:19 AM

A simplified (non-recursive) framework might look like the code below

(I have also sketched a couple of the statistical amendments)

[CODE]set {strDelim, text item delimiters} to {text item delimiters, return}

-- LIST YOUR LABELS AND THEIR DEFINITIONS
tell application id "com.omnigroup.omnifocus"
tell default document
set strResults to {
"Actions, excluding action groups: " & (do shell script "sqlite3 ~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2 'select count(*) from task where (projectinfo is null) and (childrenCount=0)';"),
"",
"Active Folders: " & (count of (flattened folders where its hidden is false)) as string,
"Dropped Folders: " & (count of (flattened folders where hidden is true)) as string,
"",
"Various other categories, and their counts",
"...",
"etc.",
"",
"Pending projects: " & (count of (flattened projects where singleton action holder is false and status is active and
((its folder is missing value) or (effectively hidden of its folder is false)) and its start date > (current date))) as string
} as string
end tell
end tell

-- AND OFFER THE RESULTS TO THE USER
display dialog strResults buttons {"Definition Cookbook", "Copy", "OK"} default button {"OK"} with title "No need for recursion ..."
set btn to button returned of result
if btn is "Copy" then
set the clipboard to strResults
else if btn is "Definition Cookbook" then
do shell script "open " & quoted form of "http://forums.omnigroup.com/showthread.php?p=84886#post84886"
end if

set text item delimiters to strDelim
[/CODE]


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

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