The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Today's Posts

 
Adjusting of AppleScript to add project, context and start date Thread Tools Search this Thread Display Modes
Yes please !
 
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
 
Exactly what I need !!
Great thanks for your prompt answer RobTrew !
 
What about adding a duration to the script?
 
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:
Originally Posted by Mburch View Post
What about adding a duration to the script?
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”})
You can adjust the duration to the length of time you want.

Quote:
Originally Posted by Mburch View Post
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.
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
 
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
 
 





All times are GMT -8. The time now is 06:24 PM.


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