The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Adjusting of AppleScript to add project, context and start date (http://forums.omnigroup.com/showthread.php?t=29790)

hubutz 2013-05-28 09:16 AM

Adjusting of AppleScript to add project, context and start date
 
Hi there,

I fould a really helpful script on asianefficiency.com, which can be used with a hazel rule ([url]http://www.asianefficiency.com/task-management/omnifocus-hotspot/[/url]).

The script automatically looks at a folder and creates a new task for new files in the folder (and moving the file away). This is quite nice, but it would be a lot more helpful for me if I could assign a project, a context and a start time (today+x).

Anyone able to help me? Didn't found a documentation of all the OmniFocus Parameters (and still if i'd found it i think i wouldn't have managed to get this done; kinda new to apple and not the biggest nerd).

Here is the script:
[CODE]
tell application "Finder" to set file_name to (name of theFile)
set theDate to current date
set theNote to "Scanned " & (theDate as string) & "

"
set projectname to "Proceed Files"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
set newTask to make new inbox task with properties {name:task_title}
set theProject to projectname
set note of newTask to theNote
tell the note of newTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell
[/CODE]

the variable "projectname" seems not to be working, I've set that to a project i have "Proceed Files" but... this is not added to the task.

Would be cool if you could help me :-)

Cheers,
Ben

RobTrew 2013-05-28 10:20 AM

You'll need to get references to Project and Context objects.

Something roughly like this:

[CODE]tell application "Finder" to set file_name to (name of theFile)

set theDate to current date
set theNote to "Scanned " & (theDate as string) & "

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
set oProj to my GetProject(it, projectname)
set oContext to my GetContext(it, ContextName)

tell oProj
tell (make new task with properties {name:task_title, context:oContext})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:false}
end tell
end tell
end tell
end tell


on GetProject(oDoc, strName)
using terms from application "OmniFocus"
tell oDoc
set lstProj to flattened projects where name = strName
if lstProj ≠ {} then
item 1 of lstProj
else
make new project with properties {name:strName}
end if
end tell
end using terms from
end GetProject

on GetContext(oDoc, strName)
using terms from application "OmniFocus"
tell oDoc
set lstContexts to flattened contexts where name = strName
if lstContexts ≠ {} then
item 1 of lstContexts
else
make new context with properties {name:strName}
end if
end tell
end using terms from
end GetContext
[/CODE]

hubutz 2013-05-28 10:24 PM

Thanks a lot, I knew i'd not understand any of this.

Hazel says that it's expecting an "end" instead of the "on GetProject(oDoc, strName)", so it's actually not working :-(

Gonna try a bit myself, will see if that works (i doubt it :-d)

RobTrew 2013-05-29 02:50 AM

It seems that Applescript code embedded in Hazel can't use function definitions (Hazel probably wraps the code in a function handler).

You should be able to unpackage the functions along these lines:

[CODE]tell application "Finder" to set file_name to (name of theFile)

set theDate to current date
set theNote to "Scanned " & (theDate as string) & "

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, ATTACHING IT TO THE SPECIFIED CONTEXT
tell oProj
tell (make new task with properties {name:task_title, context:oContext})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:false}
end tell
end tell
end tell
end tell
[/CODE]

hubutz 2013-05-29 03:07 AM

Hmm, thanks for the fast answer - this isn't producing an error in Hazel, but it doesn't create a task at all. Don't know if there is a way (for me) to see where it stucks or what it's actually doing.

RobTrew 2013-05-29 04:01 AM

[QUOTE=hubutz;124715]Hmm, thanks for the fast answer - this isn't producing an error in Hazel, but it doesn't create a task at all. Don't know if there is a way (for me) to see where it stucks or what it's actually doing.[/QUOTE]

Note that the code doesn't aim to create a task in the inbox – it should be placing it directly under the project.

hubutz 2013-05-29 06:08 AM

yeah, i got that, but actually it isn't adding a task at all, not in the inbox, not in the project... :(

Dale 2013-05-29 10:41 AM

I know this is not a full solution, but I thought you might be interested in two associated articles and scripts for creating tasks in OmniFocus via Hazel.

The first is the original David Sparks script. From this blog post [url]http://macsparky.com/blog/2012/8/applescript-omnifocus-tasks[/url]

[CODE]
-- Lovingly crafted by David Sparks, The Omni Group, and Ben Waldie -- macsparky.com

set theDate to current date
set theTask to "Pay Life Insurance"
set theNote to "Lovingly Scanned by your Mac on " & (theDate as string)

tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "Tech"
set theProject to first flattened project where its name = "Finance"
tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext}
end tell
end tell
[/CODE]

The second is from Patrick Lenz who modified David Sparks script. From this blog post [url]http://patricklenz.com/posts/create-omnifocus-tasks-via-hazel-redux/[/url]

[CODE]
tell application "Finder" to set file_name to (name of theFile)

tell application "OmniFocus"
set task_title to "Pay " & file_name
tell default document
set newTask to make new inbox task with properties {name:task_title}
tell the note of newTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell
[/CODE]

I tried combining these two scripts, but could at most only get a task with an attachment and a context into the inbox. This was what I have so far.

[CODE]
tell application "Finder" to set file_name to (name of theFile)

tell application "OmniFocus"
set task_title to "Pay " & file_name
tell default document
set theContext to first flattened context where its name = "iMac"
set newTask to make new inbox task with properties {name:task_title, context:theContext}
tell the note of newTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell
[/CODE]

I can get a task with attachment and context into the inbox. The addition of sending it to a project per the method from the David Sparks script does not work.

To get the obvious out of the way — yes, I did replace the "make new inbox task" with "make new task" when testing this with a line similar to

[CODE]
set theProject to first flattened project where its name = "Finance"[/CODE]

All comment and suggestions welcome.

Thank you in advance.

hubutz 2013-05-30 02:39 AM

[QUOTE=Dale;124723]I know this is not a full solution, but I thought you might be interested in two associated articles and scripts for creating tasks in OmniFocus via Hazel.

This was what I have so far.

[CODE]
tell application "Finder" to set file_name to (name of theFile)

tell application "OmniFocus"
set task_title to "Pay " & file_name
tell default document
set theContext to first flattened context where its name = "iMac"
set newTask to make new inbox task with properties {name:task_title, context:theContext}
tell the note of newTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell
[/CODE]

I can get a task with attachment and context into the inbox. The addition of sending it to a project per the method from the David Sparks script does not work.

To get the obvious out of the way — yes, I did replace the "make new inbox task" with "make new task" when testing this with a line similar to

[CODE]
set theProject to first flattened project where its name = "Finance"[/CODE]

All comment and suggestions welcome.

Thank you in advance.[/QUOTE]

Hi Dale,

thanks for sharing this. I've tried this one but it's not doing anything to my OmniFocus. I'm wondering if this could be because I have a german OSX?

Dale 2013-05-30 12:38 PM

I am not sure if your language setting would be affecting these scripts. I had many versions of the script silently fail within Hazel because of simple errors in the script itself. Check first that you modified "iMac" in my script from above to a context you currently have in your OmniFocus. It is not clear if you used the following line in your script or not.

[CODE]
set theProject to first flattened project where its name = "Finance"
[/CODE]

If you did; please remove the line.

Does the script work?

If the script is not working, could you test the David Sparks script and the Patrick Lens script?

1. Create a folder on you desktop named "Test" and add it to Hazel.
2. Create a rule for the folder "Test" to run if a file named "sparks.txt" is added to the folder — have this rule run the David Sparks script.
3. Create another rule for the folder "Test" to run if a file named "lens.txt" is added to the folder — have this rule run the Patrick Lens script.

Please post your results. Did my modified script run? Did the David Sparks script run? Did the Patrick Lens script run?

Thank you.

hubutz 2013-05-30 09:11 PM

Hi Dale,

thanks for that help. After putting all scripts ones after ones your's worked well - I found that i did a copy error and missed the first line.

BTW: I've edited your script a little bit to add the date of the scan (stole that at asianeffiecncy):

[CODE]
tell application "Finder" to set file_name to (name of theFile)
set theDate to current date
set theNote to "Scanned " & (theDate as string) & "

"

tell application "OmniFocus"
set task_title to "Proceed: " & file_name
tell default document
set theContext to first flattened context where its name = "Review"
set newTask to make new inbox task with properties {name:task_title, context:theContext}
set note of newTask to theNote
tell the note of newTask
make new file attachment with properties {file name:theFile, embedded:false}
end tell
end tell
end tell
[/CODE]

Thanks a lot man! To get it into the right project is quite easier as you can drag and drop a lot of tasks to a project :-)

Dale 2013-05-30 10:36 PM

It is good to hear you have something working and is useful for you. The point of my bringing up all the scripts/references was to help give background to the original script you posted and at least get that working for you.

I would strongly suggest to take a look at the script Rob Trew presented as a solution in this thread when you have time. His scripts are very well done and I use many of them in my personal workflows. Besides his script is much more sophisticated and offers more features than my simple cobbling together of these other scripts.

hubutz 2013-05-31 12:26 AM

Yeah, i'll have a look at Rob's script, maybe I'll be able to get it working :)

hubutz 2013-05-31 12:42 AM

[QUOTE=RobTrew;124712]It seems that Applescript code embedded in Hazel can't use function definitions (Hazel probably wraps the code in a function handler).

You should be able to unpackage the functions along these lines:

[CODE]tell application "Finder" to set file_name to (name of theFile)

set theDate to current date
set theNote to "Scanned " & (theDate as string) & "

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, ATTACHING IT TO THE SPECIFIED CONTEXT
tell oProj
tell (make new task with properties {name:task_title, context:oContext})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:false}
end tell
end tell
end tell
end tell
[/CODE][/QUOTE]

I have to admit that I'm really stupid. This script works like a charm if you copy it right. I forgot the first line again... Sorry for beeing so dumb!

Just one more question: Can you help me to add a Start Date for that task as well? I'd like something like "today+3".

Cheers,
Ben

PS: Rob you are truly a hero!

RobTrew 2013-05-31 10:32 AM

[QUOTE=hubutz;124781]I forgot the first line again... [/QUOTE]

No problem – easily done.

[QUOTE]a Start Date for that task as well? I'd like something like "today+3"[/QUOTE]

Perhaps something along these lines:

[CODE]tell application "Finder" to set file_name to (name of theFile)

set dteBase to current date
set theNote to "Scanned " & (dteBase as string) & "

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT,
-- ATTACHING IT TO THE SPECIFIED CONTEXT
-- AND STAMPING IT WITH A START DATE

set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
set dteStart to dteStart + (3 * days) -- and add three days

tell oProj
tell (make new task with properties {name:task_title, context:oContext, start date:dteStart})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:false}
end tell
end tell
end tell
end tell[/CODE]

Dale 2013-05-31 10:36 AM

[QUOTE=hubutz;124781]
Just one more question: Can you help me to add a Start Date for that task as well? I'd like something like "today+3".
[/QUOTE]

This works for me.

[CODE]
tell application "Finder" to set file_name to (name of theFile)

set theDate to current date

set theStartDate to current date
set time of theStartDate to 0 + (8 * hours)

set theNote to "Scanned " & (theDate as string) & "

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, ATTACHING IT TO THE SPECIFIED CONTEXT
tell oProj
tell (make new task with properties {name:task_title, context:oContext, start date:(theStartDate) + (3 * days)})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:false}
end tell
end tell
end tell
end tell
[/CODE]

To modify the time change the number of hours using 24hour time in the this line of code.

[CODE]
set time of theStartDate to 0 + (8 * hours)
[/CODE]

hubutz 2013-06-01 12:05 AM

[QUOTE=RobTrew;124800]No problem – easily done.



Perhaps something along these lines:

[CODE]tell application "Finder" to set file_name to (name of theFile)

set dteBase to current date
set theNote to "Scanned " & (dteBase as string) & "

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT,
-- ATTACHING IT TO THE SPECIFIED CONTEXT
-- AND STAMPING IT WITH A START DATE

set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
set dteStart to dteStart + (3 * days) -- and add three days

tell oProj
tell (make new task with properties {name:task_title, context:oContext, start date:dteStart})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:false}
end tell
end tell
end tell
end tell[/CODE][/QUOTE]

Thanks a lot Rob! This works perfectly and will give me some more spare time :-)

@Dale: thanks for your help as well!
But I don't get this. Why do i want to add 8 * hours? Do i have to add 72 instead of hours if i want 3 days? :)

[QUOTE=Dale;124801]
To modify the time change the number of hours using 24hour time in the this line of code.

[CODE]
set time of theStartDate to 0 + (8 * hours)
[/CODE][/QUOTE]

Dale 2013-06-01 10:24 AM

[QUOTE=hubutz;124816]
@Dale: thanks for your help as well!
But I don't get this. Why do i want to add 8 * hours? Do i have to add 72 instead of hours if i want 3 days? :)
[/QUOTE]

I had posted my script modification before I saw Rob Trew also had posted a response. My script has two parts to it; start date of 3 days from the current date, and start time of 8AM.

[B]Part one:[/B]

Set the start date to equal the current date.

[CODE]
set theStartDate to current date
[/CODE]

Added the start date property to the task to start in three days.

[CODE]
start date:(theStartDate) + (3 * days)
[/CODE]

[B]Part two:[/B]

Added the option for setting a start time to the start date being added to the task. By default the start time is the time the script is run. I wanted to set the tasks to start at a specific time.

[CODE]
set time of theStartDate to 0 + (8 * hours)
[/CODE]

The line above controls the time you want the tasks to start. The "8" means 8AM. If you wanted the tasks to begin at 8PM you would use "20". I like to use start times with my tasks and I could have explained this a lot better.

hubutz 2013-06-01 12:10 PM

Ahh, thanks - that makes sense. I think I'll have a deeper look into programming or scripting if the summer keeps sucking that much... seems to be pretty helpful and straight forward!

Loyd 2013-06-29 06:11 PM

1 Attachment(s)
Hello everyone,
Thank you RobTrew for this great script!
I just have a question about file attachment : when I set embedded:true, I get a repetition of the introduction of the task in Omnifocus indefinitely and without the file is attached.

Thank you to enlighten me.
Wonderfull Forum !!!

here is the script I've used and the image of the result :
[CODE]tell application "Finder" to set file_name to (name of theFile)

set dteBase to current date
set theNote to "Scanned " & (dteBase as string) & "

"
set projectname to "Factures à Encoder"

set ContextName to "En-Ligne"

set theTask to "Encoder: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT,
-- ATTACHING IT TO THE SPECIFIED CONTEXT
-- AND STAMPING IT WITH A START DATE

set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
set dteStart to dteStart + (10 * days) -- and add three days

tell oProj
tell (make new task with properties {name:task_title, context:oContext, start date:dteStart, flagged:true})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:true}
end tell
end tell
end tell
end tell[/CODE]

RobTrew 2013-06-30 07:42 AM

Je pense qu'il vous manque, peut-être, le chemin complet du fichier:

[CODE]tell application "Finder" to set file_name to (name of theFile)[/CODE]



[CODE]tell application "Finder" to set file_name to (POSIX path of theFile)[/CODE]

Loyd 2013-07-03 09:28 AM

Merci RobTrew !

Ta modification marche parfaitement !!
Maintenant le document est correctement "embedded"

Loyd

Loyd 2013-10-11 07:28 AM

Hello RobTrew !

How can I set a due date to the task generated by your script below ?

Thanks in advance for your time
Loyd

RobTrew 2013-10-11 08:43 AM

[QUOTE=Loyd;127896]How can I set a due date to the task generated by your script below ?[/QUOTE]

The script in post 20 of this thread ?

Loyd 2013-10-11 09:09 AM

Yes please !

RobTrew 2013-10-11 09:26 AM

If you simply wanted the DUE date to be a certain number days after the START date, then you could do something like this:

[CODE]set DAYS_FROM_START to 5

--tell application "Finder" to set theFile to (first item of (selection as list)) as alias
tell application "Finder" to set file_name to (POSIX path of theFile)

set dteBase to current date

set theNote to "Scanned " & (dteBase as string) & "

"
set projectname to "Factures à Encoder"

set ContextName to "En-Ligne"

set theTask to "Encoder: \"" & file_name & "\""

tell application "OmniFocus"
set task_title to theTask
tell default document
-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT
set lstProj to flattened projects where name = projectname
if lstProj ≠ {} then
set oProj to item 1 of lstProj
else
set oProj to (make new project with properties {name:projectname})
end if

-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
set lstContexts to flattened contexts where name = ContextName
if lstContexts ≠ {} then
set oContext to item 1 of lstContexts
else
set oContext to (make new context with properties {name:ContextName})
end if

-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT,
-- ATTACHING IT TO THE SPECIFIED CONTEXT
-- AND STAMPING IT WITH A START DATE

set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
set dteStart to dteStart + (10 * days) -- and add three days

set dteDue to dteStart + (DAYS_FROM_START * days) -- Due N days after start

tell oProj
tell (make new task with properties {name:task_title, context:oContext, start date:dteStart, due date:dteDue, flagged:true})
set its note to theNote
tell its note to make new file attachment with properties {file name:file_name, embedded:true}
end tell
end tell
end tell
end tell[/CODE]

Loyd 2013-10-11 09:54 AM

Exactly what I need !!
Great thanks for your prompt answer RobTrew !

Mburch 2014-01-21 07:56 AM

What about adding a duration to the script?

Mburch 2014-01-21 10:23 AM

Also, how would you add a Project that is part of a hierarchy? So rather than Finance in David Sparks example, how would you add Finance if it was under Personal projects? "Personal:Finance" does not seem to work.

Dale 2014-01-27 03:57 PM

[QUOTE=Mburch;129133]What about adding a duration to the script?[/QUOTE]

In the script you would add an additional condition for the task duration.

Example 15 minutes:
[CODE]tell (make new task with properties {name:task_title, context:oContext, start date:dteStart, due date:dteDue, flagged:true, estimated minutes:”15”})[/CODE]

You can adjust the duration to the length of time you want.

[QUOTE=Mburch;129135]Also, how would you add a Project that is part of a hierarchy? So rather than Finance in David Sparks example, how would you add Finance if it was under Personal projects? "Personal:Finance" does not seem to work.[/QUOTE]

It is unclear what your hierarchy is. Is “Personal” a project or a folder; and the same with "Finance"? If you have separated "Personal" and "Professional" projects by use of folders and have a "Finance" project within each the script finds the first project matching the name "Finance" and inserts the new task.

Regardless, you could state specifically the folder you wish to add a task to the project "Finance".

Simple example:
[CODE]set theDate to current date
set theTask to "New Task"
set theDuration to "15"

tell application "OmniFocus"
tell front document
set theContext to first flattened context where its name = "Mac"
set theFolder to first flattened folder where its name = "Personal"
set theProject to first flattened project of theFolder where its name = "Finance"
tell theProject to make new task with properties {name:theTask, estimated minutes:theDuration, context:theContext}
end tell
end tell[/CODE]

Mburch 2014-03-25 04:36 AM

Thanks Dale. Got it working...now how would I add a file with variable file_name as an attachment? Here's what I've got so far

tell application "Finder" to set file_name to (name of theFile)

tell application "OmniFocus"
set theTask to "Read " & file_name
set dueDate to (current date)
set time of dueDate to 0 + (16 * hours)
set startDate to (current date)
tell default document
set theContext to first flattened context where its name = "Device"
set theFolder to first flattened folder where its name = "Work"
set theProject to first flattened project of theFolder where its name = "Read"
tell theProject to make a new task with properties {name:theTask, context:theContext, due date:dueDate, start date:startDate, estimated minutes:"15"}
end tell
end tell

Dale 2014-04-11 03:58 PM

Sorry for such a late response. I have been in the new OmniFocus forum for OF2.

I am not sure if you are wanting a linked file or an embedded file.

I would suggest taking the script from Rob Trew in post [URL="http://forums.omnigroup.com/showpost.php?p=127899&postcount=26"]26[/URL] of this thread and modifying that script. You should be able to verify the current script variables are correct for you situation and add in the requirement in placing a task into a specific folder. I hope this helps.

You should also know the AppleScript library for OF2 has been changed and this can effect current scripts. I have not tested any scripts in OF2 and will probably not do so until it is officially released and determined if I am going to upgrade to the new version, continue using OF1, or moving to another solution.


All times are GMT -8. The time now is 07:38 PM.

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