Hi
I have the following script that opens websites, but only if the link is preceded by http, I would like to change that to open any like starting with “www”. Could anyone please tell me how to do that. Thanks.
– Downloaded From: http://c-command.com/scripts/omnifocus/open-links
– Last Modified: 2014-05-25
on run {}
repeat with _action in my selectedActions()
my processAction(_action)
end repeat
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 _url to _action’s name
do shell script "open " & _url’s quoted form
end tell
end processAction
Here ya go:
on run {}
repeat with _action in my selectedActions()
my processAction(_action)
end repeat
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 _url to _action's name
if _url starts with "www." then
set _url to "http:" & _url
end if
do shell script "open " & _url's quoted form
end tell
end processAction
1 Like
I think the last function needs to be written this way …
on processAction(_action)
set _url to _action's name
if _url starts with "www." then
set _url to "http:" & _url
do shell script "open " & _url's quoted form
end if
end processAction
I made these changes
- no need to call OmniFocus with a shell script command
- only do shell script when _url starts with target term
Also, while I see the cleverness with the collapsed statement calls, I think it only adds confusion. You might be surprised how often you are have been calling OmniFocus in redundant or unnecessary ways after you would write this code as one run handler without its abbreviated sub-handlers. Although I doubt this is about speed, using one run handler might be faster than using sub-sub-sub- … handler calls.
ps … @henders … Please learn how to post code in the </> code manner with indentations so that it is easier to read.
–
JJW
This has resolved my issue.
1 Like