【发布时间】:2020-01-23 12:51:02
【问题描述】:
我正在努力在 AppleScript 中概述工作流程。该脚本接受了我需要从 Omnifocus 执行的下一个任务,并要求我确定是否可以在 2 分钟或更短的时间内完成。如果可以的话,它会启动一个计时器,我希望它等到我真正完成任务。现在我会弹出一个对话框,我可以在完成后将任务标记为完成。不幸的是,我需要在 Omnifocus 中完成一些任务,而在打开对话框的情况下,我无法在 Omnifocus 中执行任何操作。
我想避免使用该对话框,以便在脚本运行时在 Omnifocus 中工作。我希望能够告诉脚本我已完成,以便它可以停止计时器,告诉我完成任务需要多长时间,然后继续在 Omnifocus 中将任务标记为完成。我最初认为最好的方法是输入一个组合键。经过一番研究,我认为我不能在 AppleScript 中做到这一点。我对如何让我在脚本中间工作然后告诉程序我完成任务的任何想法持开放态度。
这是我的代码:
on run {}
with timeout of (30 * 60) seconds
tell application "OmniFocus"
activate
end tell
tell application "OmniFocus"
tell default document to tell front document window
set perspective name to "Daily Wrap-Up"
tell content to set TreeList to (value of first leaf)
repeat with ListItem in TreeList
set ProjectName to name of containing project of ListItem as text
set TaskName to " - " & name of ListItem
set NoteName to " - " & note of ListItem
display dialog "The task is:" & return & ProjectName & TaskName & NoteName & return & "Can you do this in 2 minutes or less?" buttons {"Yes", "No"} default button "Yes"
set Button_Returned to button returned of result
if Button_Returned = "Yes" then
say "Get to work!"
set T1 to minutes of (current date)
set T1s to seconds of (current date)
display dialog "Click when done." buttons {"Complete", "Cancel"} default button "Complete"
set Button_Returned to button returned of result
if Button_Returned = "Complete" then
set T2 to minutes of (current date)
set T2s to seconds of (current date)
set TT_ to ((T2 * 60) + T2s) - ((T1 * 60) + T1s)
say "that took you" & TT_ & "seconds to complete"
display dialog ProjectName & TaskName & NoteName buttons {"Complete", "Defer", "Cancel"} default button "Complete"
set Button_Returned to button returned of result
if Button_Returned = "Complete" then
mark complete ListItem
tell application "OmniFocus"
compact default document
end tell
else if Button_Returned = "Defer" then
display dialog "Defer for how long (in minutes)?" default answer "60"
set TimeAdd to text returned of result
set defer date of ListItem to ((current date) + (TimeAdd * minutes))
tell application "OmniFocus"
compact default document
end tell
else if Button_Returned = "Cancel" then
tell application "OmniFocus"
compact default document
end tell
else if Button_Returned = "No" then
tell application "OmniFocus"
compact default document
end tell
end if
else if Button_Returned = "No" then
display dialog "Breakdown task."
set perspective name to "Projects"
end if
end if
end repeat
end tell
end tell
end timeout
end run
提前感谢您的帮助。
【问题讨论】:
-
常规的AppleScript确实做不到,但是AppleScriptObjC可以用来创建一个显示窗口或者在菜单栏中放置一个statusItem来显示经过的时间。计时器只是您手动启动/停止的一种荣誉吗?
-
是的。只是为了让我负责。我正在尝试将任务分解为小块。计时器给我反馈,以确保我成功并专注于我应该做的事情。
-
我不使用 OmniFocus,但看看您的脚本,它似乎非常可编写脚本。由于这听起来像是供个人使用的东西,只有在您专注于执行这些任务时才会运行,因此创建一个在后台闲置并每隔几秒轮询一次以检查的 保持打开状态 应用程序并非不合理项目列表中的特定任务是否已在 OmniFocus 中勾选为已完成。可能比对话框更好?
-
您可以使用保持打开的脚本应用程序来完成此操作,即使使用普通 AppleScript 也是如此,但如果您需要花里胡哨的功能,则需要使用 applescriptobjc。我将在今天晚些时候发布一个基本示例。
标签: applescript