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

 
problem with flattened tasks? (Applescript) Thread Tools Search this Thread Display Modes
Hi, I am trying to get the number of tasks done today in applescript. This is my code:

Code:
set dateToday to current date

tell application "OmniFocus"
	tell front document
		set tasksDoneToday to a reference to (flattened tasks where completion date is equal to dateToday)
		display dialog (count of tasksDoneToday)
	end tell
end tell
This return zero even though it shouldn't. Can someone try this and let me know if it works for them or what's wrong with the code? If someone can help me out it would be great. Thank you.
 
Don't have a Mac handy to test with, but I think that only gets you tasks completed exactly at midnight. You need to capture tasks completed between the start of today and the start of tomorrow...

Download Rob Trew's Where in OF script from http://bit.ly/OF-Find2 and use it to experiment with query language, or just do the whole job for you...

Last edited by whpalmer4; 2012-07-17 at 09:31 AM.. Reason: Update link
 
Quote:
Originally Posted by back2fala View Post
Hi, I am trying to get the number of tasks done today in applescript. This is my code:

Code:
completion date is equal to dateToday)
This return zero even though it shouldn't.
I can see why one might expect this to work - it's easy to forget that Applescript dates have a time component.

The time-stamp in your dateToday will be that of the instant at which the code is run. The time-stamps in your completed actions will be those of the moments of completion.

Thus, of course, no match ...

The simplest fix might look something like:

Code:
set dateToday to current date

-- STRIP THE TIME BACK TO 00:00 HOURS
set dateToday to dateToday - (time of dateToday)

tell application "OmniFocus"
	tell front document
		-- (SINCE 00:00 HRS THIS MORNING ...)
		set tasksDoneToday to a reference to (flattened tasks where completion date > dateToday) 
		display dialog (count of tasksDoneToday)
	end tell
end tell
--
 
Thanks to both of you!
 
Thanks to Rob for cleaning up after me. I was thinking of the "today" variable in his script, which behaves like your dateToday variable after the time component has been zeroed out.

However, it isn't necessarily the case that you couldn't have any matches as stated in Rob's argument. If you are syncing between devices, and the device on which you are running the script has its clock set behind that of the device on which the task was completed, you could get a match if you both sync and run the script at precisely the right moments, because the task could briefly appear to have been completed in the future :-)
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem: copy as applescript | osascript - gshenaut OmniGraffle General 7 2013-01-30 02:16 PM
Problem With Saving Tasks Lnaccarato OmniFocus 1 for Mac 2 2011-01-17 07:03 AM
Problem finding tasks with no context Tim1 OmniFocus 1 for Mac 2 2010-10-24 07:03 AM
Applescript Help: getting a list of tasks tweir OmniPlan General 3 2007-01-10 02:33 PM
SP17 AppleScript Problem Chucky OmniWeb Bug Reports 2 2006-07-19 05:22 PM


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


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