Created
January 17, 2017 08:58
-
-
Save helmuthauser/18d560966e22c91ae9ef4ddd39eafed5 to your computer and use it in GitHub Desktop.
AppleScript that defers highlighted tasks in Omnifocus to random date in the future (like in the iOS version of Omnifocus)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- based on a script originally file downloaded from: | |
-- http://c-command.com/scripts/omnifocus/defer-to-tomorrow | |
-- | |
-- ======================================== | |
-- Script to defer Omnifocus task to | |
-- random date in the future (emulation of "defer to random date" from iOS version | |
-- ======================================== | |
-- It chooses a random number of days ranging from 14 to 90 days and adds to today's date | |
-- NB: That's the same values Omnifocus uses in their iOS version | |
-- ======================================== | |
-- If you want to use a different range | |
-- change the values for "lower_limit" and "upper_limit" (see below) | |
-- ======================================== | |
-- by Helmut Hauser | |
-- September 7, 2016 | |
-- http://www.worksmartandberemarkable.com | |
-- ======================================== | |
on run {} | |
repeat with _action in my selectedActions() | |
my processAction(_action) | |
end repeat | |
tell application "OmniFocus" | |
tell default document | |
compact | |
end tell | |
end tell | |
end run | |
on selectedActions() | |
tell application "OmniFocus" | |
return my filterValues(my selectedValues(), {inbox task, task, available task, remaining task}) | |
end tell | |
end selectedActions | |
on selectedValues() | |
tell application "OmniFocus" | |
return value of selected trees of content of first document window of front document | |
end tell | |
end selectedValues | |
on filterValues(_values, _classes) | |
tell application "OmniFocus" | |
set _result to {} | |
repeat with _value in _values | |
if _classes contains _value's class then | |
copy _value to end of _result | |
end if | |
end repeat | |
return _result | |
end tell | |
end filterValues | |
on processAction(_action) | |
tell application "OmniFocus" | |
set _action's defer date to my calculateDate(_action's defer date) | |
end tell | |
end processAction | |
on calculateDate(_oldDate) | |
if _oldDate is missing value then | |
return my myDeferDate() | |
else | |
-- return (my midnightTomorrow()) + (time of _oldDate) | |
return (my myDeferDate()) | |
end if | |
end calculateDate | |
---------------------------------------- | |
-- Here happens the magic | |
-- Make changes here to adapt the scrip | |
-- to your needs | |
---------------------------------------- | |
on myDeferDate() | |
set _date to current date | |
set lower_limit to 14 -- number of minimum days | |
set upper_limit to 90 -- number of maximum days | |
-- produce a random value | |
set random_days to random number from lower_limit to upper_limit | |
set day of _date to ((_date's day) + random_days) | |
---------------------------------------- | |
-- To set the time you have to change the next line: | |
-- e.g., for 05:00 (5 AM): set time of _date to ( 5 * 3600) | |
-- e.g., for 09:00 (9 AM): set time of _date to ( 9 * 3600) | |
-- e.g., for 14:00 (2 PM): set time of _date to (14 * 3600) | |
-- e.g., for 20:00 (8 PM): set time of _date to (20 * 3600) | |
set time of _date to (5 * 3600) | |
---------------------------------------- | |
-- ======================================== | |
-- ======================================== | |
return _date | |
end myDeferDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment