Skip to content

Instantly share code, notes, and snippets.

@ImSingee
Created August 26, 2019 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ImSingee/b97836f56c77be0f9ebaf441c3925cf7 to your computer and use it in GitHub Desktop.
Save ImSingee/b97836f56c77be0f9ebaf441c3925cf7 to your computer and use it in GitHub Desktop.
OmniFocus-随机设定推迟时间,将任务随机推迟至 14-90 天后的 5:00(推迟日期的上下界和时间可以在代码中相应位置修改)
--
-- 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