Skip to content

Instantly share code, notes, and snippets.

@ImSingee
Created August 26, 2019 11:01
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/d8afc2c26931f2768d3dfeb0c2fdfb14 to your computer and use it in GitHub Desktop.
Save ImSingee/d8afc2c26931f2768d3dfeb0c2fdfb14 to your computer and use it in GitHub Desktop.
OmniFocus-打开动作网址,可以自动从父任务/父项目获取网址打开,可以设定 NEED_CONFIRM 来选择是否在打开网址前询问
global NEED_CONFIRM
on run {}
set NEED_CONFIRM to true
set theSelecteditems to my selectedActions()
if (count of theSelecteditems) is equal to 0 then
display alert "请选择一个有效的动作" as critical
return
end if
repeat with _action in theSelecteditems
my processAction(_action)
end repeat
end run
on selectedActions()
tell application "OmniFocus"
return my selectedValues()
--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 fetchUrl(_task)
tell application "OmniFocus"
set _note to _task's note
set _script to "echo '" & _note & "' | grep -o 'https\\?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]\\+[-A-Za-z0-9+&@#/%=~_|]' | head -1"
set _url to do shell script _script
if _url is not equal to "" then
return _url
end if
set _parent to _task's parent task
if _parent is equal to missing value then
return missing value
end if
return my fetchUrl(_parent)
end tell
end fetchUrl
on processAction(_action)
--tell application "OmniFocus"
set _url to my fetchUrl(_action)
if _url is missing value then
display alert "网址不存在" message "「" & _action's name & "」的描述中不存在网址" as critical
return
end if
if NEED_CONFIRM is equal to true then
try
display dialog "即将打开: " & _url
do shell script "open " & _url's quoted form
end try
else
do shell script "open " & _url's quoted form
end if
--end tell
end processAction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment