View Single Post
Quote:
Originally Posted by Lucas View Post
This is an example of setting context for new items in script:

tell application "OmniFocus"
set theName to "Hello"
set theContent to "Some content"
set theContext to context "Home Office" of context "Work" of first document
tell first document
set theTask to make new inbox task with properties {name:theName, note:theContent, context:theContext}
Okay, here's the original code, that actually works—it will put items into my OF inbox:

Code:
tell application "OmniFocus"
		set messageStart to (offset of "added to reqall" in theContent) + 18
		set messageEnd to (offset of "Edit this item" in theContent) - 2
		set taskName to rich text messageStart through messageEnd of theContent
		if (includeSender) then
			set taskName to taskName & "—" & messageSender
		end if
		set theDoc to default document
		tell theDoc
			set propRecord to {name:taskName}
			set theTask to make new inbox task with properties propRecord
		end tell
		tell theTask
			set start date to theDate
			set due date to theDate
			set note to return & return
			tell note
				set theURL to "message://<" & messageId & ">"
				set linkText to theURL
				insert linkText at before first character
				set value of attribute "link" of style of paragraph 1 to theURL
			end tell
		end tell
Now if I understand you correctly, to get the items automatically assigned to a context "ReQall," I would do something like this:

Code:
tell application "OmniFocus"
		set messageStart to (offset of "added to reqall" in theContent) + 18
		set messageEnd to (offset of "Edit this item" in theContent) - 2
		set taskName to rich text messageStart through messageEnd of theContent
		set taskContext to "ReQall"
                if (includeSender) then
			set taskName to taskName & "—" & messageSender
		end if
		set theDoc to default document
		tell theDoc
			set propRecord to {name:taskName, context:taskContext}
			set theTask to make new inbox task with properties propRecord
		end tell
		tell theTask
			set start date to theDate
			set due date to theDate
			set note to return & return
			tell note
				set theURL to "message://<" & messageId & ">"
				set linkText to theURL
				insert linkText at before first character
				set value of attribute "link" of style of paragraph 1 to theURL
			end tell
		end tell
This doesn't work—it doesn't seem to do anything.

And in your example, I don't understand the line:

set theContext to context "Home Office" of context "Work" of first document

That would seem to set the context to a "Home Office" subset of "Work," which I don't have (also, the macro is working with default document).

Any help would be appreciated!