The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Simple Task Creation Script (http://forums.omnigroup.com/showthread.php?t=22410)

gotrevgo 2011-10-18 05:36 PM

Simple Task Creation Script
 
Hey folks,

I'm sorry this is such a stupid question. I just need a script that creates a task with the same name as a variable in AppleScript. I've found a bunch of other scripts that create events (like the MailAction script inside of OF's bundle) but they're doing a lot of other stuff so I'm struggling to pair it down to something as simple as "create task with the name variableName".

FWIW, this is for Siri integration without using e-mail. It's complicated to setup at first, and requires an always on machine, but does the trick. Basically it imports reminders into OF so you can say "remind me to…" instead of "e-mail Task Contact 'task name'". I'll definitely share the complete solution when it works. I have everything working I just need the last little bit to get it into OmniFocus.

If I could also get a script that will do the above and let me specify a context from a variable I think I might be able to hack "Remind me to get milk, context Groceries" but I'm not 100% sure because it requires some more text processing.

Thanks! OF support pointed me here, they don't seem to have a simple create script example.

RobTrew 2011-10-19 10:57 AM

The main elements might look something like this:

[CODE]on run
set {strProj, strContext, strTask} to {"Proj1", "Context3", "TaskTitle"}

MakeTask(strProj, strContext, strTask)
end run

on MakeTask(strProj, strContext, strTask)
tell application id "OFOC"
tell default document

-- WHERE WILL IT GO (A PROJECT OR THE INBOX) ?
if strProj ≠ "" then
set lstProj to flattened projects where name = strProj
if lstProj ≠ {} then
set oProj to first item of lstProj
else
set oProj to make new project with properties {name:strProj}
end if

tell oProj to set oTask to (make new task with properties {name:strTask})
else
set oTask to (make new inbox task with properties {name:strTask})
end if

-- WHICH CONTEXT IF ANY ?
if strContext ≠ "" then
set lstContext to flattened contexts where name = strContext
if lstContext ≠ {} then
set oContext to first item of lstContext
else
set oContext to make new context with properties {name:strContext}
end if
set context of oTask to oContext
end if
end tell

return oTask
end tell
end MakeTask[/CODE]


All times are GMT -8. The time now is 11:09 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.