PDA

View Full Version : Defer (or 'snooze') tasks/projects


dbyler
2008-02-04, 08:40 PM
Here's an all-purpose task/project defer script that lets you push back projects and tasks by a given number of days (default 1, but you can enter an arbitrary number at runtime). It also lets you defer just the due date or both the start and due dates.

My original purpose was to get around the lack of a weekday option for recurring tasks, but I find myself using it all the time.

More info and download here:

http://bylr.net/3/2008/02/omnifocus-defer-script/

spnyc
2008-02-05, 05:17 AM
awesome. awesome. awesome.

i know we're not *supposed* to do this in the GTD world, but i find myself needing to do triage during frantic days, and you've just saved me much typing and thus precious time.

librarymonkey27
2008-02-05, 07:37 PM
I just finished listening to the David Allen book and I don't see why this isn't okay.

there are things that don't take two days, you can't delegate and can't be done on a certain date


for example. I wanted to do my grocery shopping yesterday, but I was delayed at the office, so I never got out to do the task. Still need groceries, they aren't on hold

they just need to be shopped for on another day


any how, great script

spnyc
2008-02-05, 08:57 PM
@librarymonkey27
i hear you and i guess as always it comes down to personal preference and what works for you, but i thought true GTD specified that dates are to be considered sacred and only used when a task has to be done on a specific day.

i definitely am not that strict, and use the start date/completed date features all the time to tickle tasks

dbyler
2008-02-06, 06:05 AM
If memory serves, Mr Allan holds the calendar as sacred, inviolable space – not dates in general.

My company uses timesheets, for instance, that are required to be filled out by 10:00 every morning. I don't want to clutter my calendar with an appointment, but this still needs to be done -- and OmniFocus is the perfect tool to gently remind me at 9:50 (via Growl) that my timesheet is due. I find it useful to just skip the weekend (defer 2 days).

dbyler
2008-02-06, 06:12 AM
Another thought: I'd rather use flags to indicate importance and dates to indicate urgency (in the Covey sense). That way I can filter on flagged tasks to get a sense of my 'big rocks' and use this script to swat the urgent/unimportant tasks out of the way if necessary.

narvik04
2008-03-19, 04:51 PM
Hello,
nice script !
But I always have to run it in the finder menu.
I dont get it into the toolbar of omnifocus. There is no Icon called Defer, I can add to the toolbar. Did I miss something ?

Best Regards
Marc

librarymonkey27
2008-03-19, 05:09 PM
you should be able to get it into your toolbar, that is how I use it

I made my own icon of a guy sleeping on the couch.

dbyler
2008-03-20, 01:09 PM
Marc, did you put the script in ~/Scripts/Application Support/OmniFocus? It needs to be there for OmniFocus to see it.

Once the script is there, go to OmniFocus' View Menu > Customize Toolbar... You should see the script there.

Librarymonkey27, I'd love to see your icon if you don't mind sharing.

librarymonkey27
2008-03-20, 01:39 PM
http://media-files.gather.com/images/d399/d558/d744/d224/d96/f3/full.jpg

dbyler
2008-03-21, 06:03 AM
Librarymonkey: Awesome. :)

librarymonkey27
2008-03-21, 07:06 PM
feel free to use it if you like

narvik04
2008-03-29, 04:54 AM
Hello dbyler,
now it works. I forgot to create the application folder...
So now i got the defer icon in the toolbar.
Thank you very much for answering so fast.
Best Regards
Marc

curt.clifton
2008-11-12, 01:41 PM
I found a few bugs in the script, particularly with handling multiple selections. I also made deferral of both start and due dates the default. Here's the updated code:


(*
This script takes the currently selected actions or projects and defers, or "snoozes", them by the user-specified number of days.
The user may snooze just the due date or both the start and due dates (useful for skipping weekends for daily recurring tasks).

version 0.1, by Dan Byler

Copyright © 2008, Daniel N. Byler (contact: dbyler@gmail.com)

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

• Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

• Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

version 0.1: Original release

Installation: Copy to ~/Library/Scripts/Applications/Omnifocus
If desired, add to the OmniFocus toolbar using View > Customize Toolbar... within OmniFocus

Known bugs:
• When the script is invoked from the OmniFocus toolbar and canceled, OmniFocus returns an error. This issue does not occur when invoked from the script menu, a Quicksilver trigger, etc.

*)

property showAlert : true --if true, will display success/failure alerts
property useGrowl : true --if true, will use Growl for success/failure alerts
property defaultSnooze : 1 --number of days to defer by default

property alertItemNum : ""
property alertDayNum : ""
-- property successTot : 0
property growlAppName : "Dan's Scripts"
property allNotifications : {"General", "Error"}
property enabledNotifications : {"General", "Error"}
property iconApplication : "OmniFocus.app"


tell application "OmniFocus"
tell front document
tell (first document window whose index is 1)
set theSelectedItems to selected trees of content
set numItems to (count items of theSelectedItems)
if numItems is 0 then
set alertName to "Error"
set alertTitle to "Script failure"
set alertText to "No valid task(s) selected"
my notify(alertName, alertTitle, alertText)
return
end if

display dialog "Defer for how many days?" default answer defaultSnooze buttons {"Cancel", "OK"} default button 2
(* if (the button returned of the result) is not "OK" then
return
end if *)
set snoozeLength to (the text returned of the result) as integer
if snoozeLength is not 1 then
set alertDayNum to "s"
end if
set changeScopeQuery to display dialog "Modify start and due dates?" buttons {"Cancel", "Due Only", "Start and Due"} default button 3 with icon caution giving up after 60
set changeScope to button returned of changeScopeQuery
if changeScope is "Cancel" then
return
else if changeScope is "Start and Due" then
set modifyStartDate to true
else if changeScope is "Due Only" then
set modifyStartDate to false
end if
set selectNum to numItems
set successTot to 0
repeat while selectNum > 0
set selectedItem to value of item selectNum of theSelectedItems
set succeeded to my defer(selectedItem, snoozeLength, modifyStartDate)
if succeeded then set successTot to successTot + 1
set selectNum to selectNum - 1
end repeat
set alertName to "General"
set alertTitle to "Script complete"
if successTot > 1 then set alertItemNum to "s"
set alertText to successTot & " item" & alertItemNum & " deferred " & snoozeLength & " day" & alertDayNum & ". (" & changeScope & ")" as string
end tell
end tell
my notify(alertName, alertTitle, alertText)
end tell

on defer(selectedItem, snoozeLength, modifyStartDate)
set success to false
tell application "OmniFocus"
set theDueDate to due date of selectedItem
if (theDueDate is not missing value) then
set newDue to (theDueDate + (86400 * snoozeLength))
set due date of selectedItem to newDue
set success to true
end if
if modifyStartDate is true then
set theStartDate to start date of selectedItem
if (theStartDate is not missing value) then
set newStart to (theStartDate + (86400 * snoozeLength))
set start date of selectedItem to newStart
set success to true
end if
end if
end tell
return success
end defer


on notify(alertName, alertTitle, alertText)
if showAlert is false then
return
else if useGrowl is true then
tell application "GrowlHelperApp"
register as application growlAppName all notifications allNotifications default notifications enabledNotifications icon of application iconApplication
notify with name alertName title alertTitle application name growlAppName description alertText
end tell
else
display dialog alertText with icon 1
end if
end notify

fozziebear
2008-11-17, 12:18 PM
Hi

I'm trying to add this script to the toolbar, with no luck. I've put it in

~/Library/Scripts/OmniFocus

which I believe is the right place, and it show up in the apple scripts menu on the RH side of the menu bar, but I can't work out how to drag and drop it onto the toolbar. It doesn't appear on the toolbar customization palette, and it won't drop anywhere.

I'm sure I'm doing something obviously stupid/wrong, but I can't work out what it is. Could anyone help, please?

(I'm running OF 1.5, latest RC).

thanks
FB

kaijin
2008-11-17, 12:54 PM
I'm trying to add this script to the toolbar, with no luck. I've put it in

~/Library/Scripts/OmniFocus

which I believe is the right place, and it show up in the apple scripts menu on the RH side of the menu bar, but I can't work out how to drag and drop it onto the toolbar. It doesn't appear on the toolbar customization palette, and it won't drop anywhere.

Place the script in ~/Library/Scripts/Applications/OmniFocus. It should then appear as an option for the toolbar customization.

henri
2009-02-14, 04:40 PM
I found a few bugs in the script, particularly with handling multiple selections. I also made deferral of both start and due dates the default. Here's the updated code:


This is fantastic, and I use it all the time. Thanks!

It also works with negative numbers of days, if you want to do something sooner.

dbyler
2009-02-19, 01:28 PM
Curt, thanks for your bug fixes—I was having trouble with a couple of them. Those changes and a few others are incorporated in a new version...

Release notes & download here (http://bylr.net/3/2009/02/omnifocus-defer-script-updated/)

Greg Jones
2009-02-20, 03:22 AM
Thanks for the update on this script. I'll add that that one thing that I would like to see in this is the option to modify start only, due only, or start and due. I tried modifying this script a while back to see if I could do it, but I'm not script-savvy enough to make it work. One limitation that I ran into right away is that apparently one cannot have 4 buttons in a script dialog, so if there are options to modify start, due, both, then there cannot be a cancel button.

dbyler
2009-02-26, 06:53 PM
Greg,

Good idea. I thought about wrapping "Start only" into the Defer script but decided it's conceptually different enough to "snooze" an item (leaving the due date intact) than to "defer" it (pushing the whole item back)... so I adapted this into a new "Snooze" script that does what you want.

More info & download here (http://bylr.net/3/2009/02/omnifocus-snooze-script/).

Greg Jones
2009-02-27, 01:12 AM
That's exactly what I need and it works well-thanks!

BevvyB
2009-04-10, 05:29 AM
Is there any way that this can automatically fill in today's date for unscheduled tasks that you want to move?

At the moment if you use it on a task which doesn't have a specific date it does nothing as it doesn't realise that even though the date field is blank, you may still want to move this action to a few days from the current date.

dbyler
2009-04-13, 12:36 PM
Bevvy—for unscheduled tasks that you want to move, do you want to avoid seeing them for the specified number of days? If so, this "Snooze" script might suit your needs:

http://bylr.net/3/2009/02/omnifocus-snooze-script/

henri
2009-04-13, 08:09 PM
Is there any way that this can automatically fill in today's date for unscheduled tasks that you want to move?

At the moment if you use it on a task which doesn't have a specific date it does nothing as it doesn't realise that even though the date field is blank, you may still want to move this action to a few days from the current date.

I too would find this convenient. This way I wouldn't have to have one script for snooze, and another for defer.

jasong
2009-10-09, 03:26 PM
Hi there. I'm glad I searched for a script before trying to write one myself.

I don't seem to be able to select an item on the sidebar and run the script; it gives an error that there are "No valid task(s) selected".

It works if I select an item in the main outline list.

Is this a limitation of the script or of OF?

curt.clifton
2009-10-09, 03:30 PM
Script. It's possible to get the selection in the sidebar also.

skillet
2011-07-06, 09:49 AM
Thanks Dan and Curt for this excellent script.

I modified the script slightly to include a start other than 12:AM so you can better filter actions visually that start during work hours. This way the grouping by start date will show "Start Today" items to do in the morning a little quicker. Using Remaining or Available under "Availability Filter helps me see what I need to do at home a little quicker (like a context for time).

It is set to 8AM but just change the number in the script at the top and the time in the dialog.

--Based on the snooze script at http://bylr.net/files/omnifocus/


(*
# DESCRIPTION #

This script "snoozes" the currently selected actions or projects by setting the start date to given number of days in the future.


# LICENSE #

Copyright © 2010 Dan Byler (contact: dbyler@gmail.com)
Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)


# CHANGE HISTORY #

0.2c (2010-06-22)
- Actual fix for autosave

0.2b (2010-06-21)
- Encapsulated autosave in "try" statements in case this fails

0.2 (2010-06-15)
- Fixed Growl code
- Added performance optimization (thanks, Curt Clifton)
- Changed from LGPL to MIT license (MIT is less restrictive)

0.1: Original release. (Thanks to Curt Clifton, Nanovivid, and Macfaninpdx for various pieces of code)


# INSTALLATION #

- Copy to ~/Library/Scripts/Applications/Omnifocus
- If desired, add to the OmniFocus toolbar using View > Customize Toolbar... within OmniFocus


# KNOWN BUGS #

- When the script is invoked from the OmniFocus toolbar and canceled, OmniFocus returns an error. This issue does not occur when invoked from the script menu, a FastScripts or Quicksilver trigger, etc.

*)

property showAlert : false --if true, will display success/failure alerts
property useGrowl : true --if true, will use Growl for success/failure alerts
property defaultSnooze : 1 --number of days to snooze by default
property alertItemNum : ""
property alertDayNum : ""
property growlAppName : "Dan's Scripts"
property allNotifications : {"General", "Error"}
property enabledNotifications : {"General", "Error"}
property iconApplication : "OmniFocus.app"
property startTime : 8 --Military time to start

tell application "OmniFocus"
tell front document
tell (first document window whose index is 1)
set theSelectedItems to selected trees of content
set numItems to (count items of theSelectedItems)
if numItems is 0 then
set alertName to "Error"
set alertTitle to "Script failure"
set alertText to "No valid task(s) selected"
my notify(alertName, alertTitle, alertText)
return
end if

display dialog "Snooze start date for how many days from today? Start time will be 8:AM" default answer defaultSnooze buttons {"Cancel", "OK"} default button 2
set snoozeLength to (the text returned of the result) as integer
set todayStart to (current date) - (get time of (current date))
if snoozeLength is not 1 then
set alertDayNum to "s"
end if
set selectNum to numItems
set successTot to 0
set autosave to false
repeat while selectNum > 0
set selectedItem to value of item selectNum of theSelectedItems
set succeeded to my snooze(selectedItem, todayStart, snoozeLength)
if succeeded then set successTot to successTot + 1
set selectNum to selectNum - 1
end repeat
set autosave to true
set alertName to "General"
set alertTitle to "Script complete"
if successTot > 1 then set alertItemNum to "s"
set alertText to successTot & " item" & alertItemNum & " snoozed. The item" & alertItemNum & " will become available in " & snoozeLength & " day" & alertDayNum & "." as string
end tell
end tell
my notify(alertName, alertTitle, alertText)
end tell

on snooze(selectedItem, todayStart, snoozeLength)
set success to false
tell application "OmniFocus"
try
set newStart to (todayStart + (86400 * snoozeLength + (startTime * 3600)))
set start date of selectedItem to newStart
set success to true
end try
end tell
return success
end snooze

on notify(alertName, alertTitle, alertText)
if showAlert is false then
return
else if useGrowl is true then
--check to make sure Growl is running
tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
if GrowlRunning = 0 then
--try to activate Growl
try
do shell script "/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/Contents/MacOS/GrowlHelperApp > /dev/null 2>&1 &"
do shell script "~/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/Contents/MacOS/GrowlHelperApp > /dev/null 2>&1 &"
end try
delay 0.2
tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
end if
--notify
if GrowlRunning ≥ 1 then
try
tell application "GrowlHelperApp"
register as application growlAppName all notifications allNotifications default notifications allNotifications icon of application iconApplication
notify with name alertName title alertTitle application name growlAppName description alertText
end tell
end try
else
set alertText to alertText & " \r \rp.s. Don't worry—the Growl notification failed but the script was successful."
display dialog alertText with icon 1
end if
else
display dialog alertText with icon 1
end if
end notify

dbyler
2011-07-07, 07:10 PM
Thanks, everyone, for your input.

Bevvy, Henri—I've just pushed a new version to Github that addresses your concerns.

Skillet—it includes the ability to set start time for "snoozed" items, although still respects the times of existing start/due dates.

Jasong—I haven't added the ability to select items from the sidebar because it's sometimes not visually obvious what's selected and I don't want to mistakenly trigger the script. Let me know if you feel strongly about this though and I can add it.

Here's the changelog:

0.4 (2011-07-07)
- New option to set start time (Default: 8am)
- New snoozeUnscheduledItems option (default: True) lets you push the start date of unscheduled items.
- No longer fails when a Grouping divider is selected
- Reorganized; incorporated Rob Trew's method to get items from OmniFocus
- Fixes potential issue when launching from OmniFocus toolbar

Source here (https://github.com/dbyler/omnifocus-scripts/blob/master/Defer.scpt); direct download here (https://github.com/dbyler/omnifocus-scripts/raw/master/Defer.scpt)

skillet
2011-07-08, 12:50 PM
Although still respects the times of existing start/due dates.


Nice work Dan, I will be using both now.

I like both approaches
1) Always Deferring by the amount from the current set date (i.e. repeating tasks that aren't going to happen this week that you want to keep on the same days)

2) Having all the actions start on the same day regardless of when they were set to originally start (I use more often).

Keep up the nice work, very useful.

henri
2011-07-12, 01:52 PM
It would be great if the script was able to defer a project due date, when invoked from an action (in that project) that has no due date of its own. (OF assumes the action is due when the project is due, so this would make sense.)

dbyler
2011-07-13, 04:06 PM
Henri—interesting thought. I'd be a little hesitant to push back a project when one of its mere tasks is selected, but I definitely see why you'd want to do that. Let me think about that a little more...

whpalmer4
2011-07-13, 04:47 PM
It's a bit tricky because while you can set the due date on an action, OmniFocus will treat it as having the most restrictive due date of any ancestor, leading to situations like this:

http://img824.imageshack.us/img824/5865/screenshot20110713at531.png (http://imageshack.us/photo/my-images/824/screenshot20110713at531.png/)

(obviously, this is an action from a project which is due today). If you query OmniFocus with Applescript for a task's due date, it appears you do not get the effective due date (today, in my example).

Maybe the safe thing to do is to at least warn the user that the deferred date isn't actually the effective date? Unfortunately, I think you have to walk up the container chain to do that.

dbyler
2011-07-14, 03:31 PM
Okay, here's (https://github.com/dbyler/omnifocus-scripts/blob/fee946a10d6c64401a9901d371348c591269671c/Defer.scpt) a new version that checks for discrepancies between actual and effective Start and Due dates and warns you if there's a mismatch. (You can turn off the warning if you want.)

It also lets you skip the second dialog box if you always change the same parameters (Due only or Start and Due).

I opted not to change the ancestors because that seemed like it would introduce too much uncertainty into the workflow. A warning seemed like a better middle ground. (I'd have loved to make the Growl notifications clickable to open the project in question, but you can't do that with AppleScript.)

Let me know what you think of this change.

vfatia
2011-08-01, 02:43 PM
Hello,

When running the latest sneaky peek in Lion there is the possibility of running the app in fullscreen.

If I run the script I get the error "Can’t get document window 1 of document 1 whose index = 1. Invalid index". I have already addressed the ninjas but they said fullscreen didn't allow getting windows and they were also looking for a workaround… :(


Any ideas?!

RobTrew
2011-08-01, 02:57 PM
Hello,

When running the latest sneaky peek in Lion there is the possibility of running the app in fullscreen.

If I run the script I get the error "Can’t get document window 1 of document 1 whose index = 1. Invalid index". I have already addressed the ninjas but they said fullscreen didn't allow getting windows and they were also looking for a workaround… :(


Any ideas?!

OS upgrades usually do break at least a few scripts.

If one's work-flows depend on scripts to any significant extent, it's usually better to delay upgrading the OS, let the early adopters discover the problems, and give the developers some time to develop solutions.

I personally won't go anywhere near Lion before the new year ... and even then only once compelling disadvantages in sticking with Snow Leopard are clearly present - right now it's not very easy to see any ...

vfatia
2011-08-02, 09:42 AM
OS upgrades usually do break at least a few scripts.

If one's work-flows depend on scripts to any significant extent, it's usually better to delay upgrading the OS, let the early adopters discover the problems, and give the developers some time to develop solutions.

I personally won't go anywhere near Lion before the new year ... and even then only once compelling disadvantages in sticking with Snow Leopard are clearly present - right now it's not very easy to see any ...

I do agree, but trying the new shining thing as a certain appeal. This isn't a deal breaker, if it was time machine to the rescue! ;)

RobTrew
2011-08-08, 05:23 AM
I don't have a copy of Lion to hand, but just in case the problem is specific to the document window 1 of document 1 whose index = 1 idiom, it might be worth testing this similar script (http://bit.ly/OFStartDue), which bypasses the index query.

dbyler
2011-08-29, 05:26 PM
vfatia, just saw your post... it's working fine for me when running OmniFocus (1.9.3 sneaky peek v77.75.10 r154699) in Lion (10.7.1) in full-screen mode, activating the script using Fastscripts.

Is it still broken for you?