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 > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Adding Project and Context Thread Tools Search this Thread Display Modes
OK still working on this folderAction. I would like to learn how to add a Project and a Context to a task. The code below is working just like I want except I would like to add a default project of "Miscellaneous" and a default context of "Unassigned" Thanks for any insight you may provide.

d


Code:
on adding folder items to my_folder after receiving the_files
	repeat with i from 1 to number of items in the_files
		tell application "OmniFocus"
			launch
			try
				set this_file to (item i of the_files)
				tell application "Finder"
					activate
					open document file this_file using application file "Tex-Edit Plus.app" of folder "Tex-Edit Plus" of folder "Applications" of startup disk
					tell application "Tex-Edit Plus"
						activate
						delete text from line 1 to line 7 of window 1
						select contents of window 1
						set singleTask to false
						set theText to contents of window 1
						close window 1 without saving
						tell application "OmniFocus"
							set singleTask to true
							tell default document
								set myNewTasks to parse tasks with transport text theText as single task singleTask
							end tell
							set start date of first item of myNewTasks to (current date) + 1 * days
							set due date of first item of myNewTasks to (current date) + 4 * days
						end tell
					end tell
				end tell
				add this_file
			end try
		end tell
	end repeat
end adding folder items to
 
In the OmniFocus app:

Help > Release Notes > Archive (a link at the top)

Then search for "November 2" (no year specified)

This seems to be the fullest summary of the "parse tasks" syntax, including the specification of project & context.

(Might be worth a suggestion to Help > Support that it could usefully be included in the main help file)

--

Last edited by RobTrew; 2010-10-10 at 12:54 AM..
 
Quote:
Originally Posted by RobTrew View Post
In the OmniFocus app:

Help > Release Notes > Archive (a link at the top)

Then search for "November 2" (no year specified)

This seems to be the fullest summary of the "parse tasks" syntax, including the specification of project & context.

(Might be worth a suggestion to Help > Support that it could usefully be included in the main help file)

--

I thank you for your post and have looked at the info you suggested above but it looked to me to be info on parsing from an email to OF. I already know the Project and context I want to add but don't seem to have the syntax down correctly to add this info. I want a default project of "Miscellaneous" with a default context of "Unassigned" Below is the current state of my folderactions script. Thanks!

Code:
on adding folder items to my_folder after receiving the_files
	repeat with i from 1 to number of items in the_files
		tell application "OmniFocus"
			launch
			try
				set this_file to (item i of the_files)
				tell application "Finder"
					activate
					--set theText to read file ":Users:RoonToon:Desktop:Request.txt" -- open the file and get the contents
					set theText to read this_file
					set {od, my text item delimiters} to {my text item delimiters, "EndOfRequest"} -- set the text marker
					set requestText to text item 1 of theText -- get everything up to the marker
					set my text item delimiters to od -- clean up
					set reqLines to paragraphs of requestText -- get the lines of text
					set reqLines to items 8 through end of reqLines -- strip off the first 7 lines
					set reqLines to items 1 through 5 of reqLines & items 7 through end of reqLines -- strip line 6
					set reqLines to items 1 through 6 of reqLines & items 9 through end of reqLines -- strip lines 7 - 12
					set my text item delimiters to return
					set reqLines to reqLines as text -- convert the list back to text
					set my text item delimiters to od -- clean up
					set theText to text 2 through end of reqLines
					tell application "OmniFocus"
						set singleTask to true
						tell default document
							set myNewTasks to parse tasks with transport text theText as single task singleTask
						end tell
						set start date of first item of myNewTasks to (current date) + 1 * days
						set due date of first item of myNewTasks to (current date) + 4 * days
					end tell
				end tell			
				add this_file
			end try
		end tell
	end repeat
end adding folder items to
 
Quote:
Originally Posted by roontoon View Post
it looked to me to be info on parsing from an email to OF
set theResult to parse tasks with transport text unicode text

is agnostic with regard to the source of the unicode text.

-- Action > Project @ Context

If your theText variable only contains the name of the action, you simply need to append the name of a project, preceded by > and/or the name of a context preceded by @

If there are multiple actions, each new one should start with "--" at the beginning of the line.

--
 
Quote:
Originally Posted by RobTrew View Post
set theResult to parse tasks with transport text unicode text

is agnostic with regard to the source of the unicode text.

-- Action > Project @ Context

If your theText variable only contains the name of the action, you simply need to append the name of a project, preceded by > and/or the name of a context preceded by @

If there are multiple actions, each new one should start with "--" at the beginning of the line.

--

So when OF parses the text that is passed to it no matter from were if it encounters a > then it assigns the following text to the Project and like wise for the context. Now for some clarification... I have added the two lines in red below to my script. I am now getting an Omnifocus Applescript error : "Can't make Unicode text into type rich text". I tend to learn coding by example and I have yet to find any examples of where the project is added in this way. Thanks again for you help.


set my text item delimiters to return
set reqLines to reqLines as text -- convert the list back to text
set my text item delimiters to od -- clean up
set theText to text 2 through end of reqLines
set theText to theText & ">" & defaultProject
tell application "OmniFocus"
set MyDoc to default document
tell application "OmniFocus" to tell MyDoc
set singleTask to true
set theText to parse tasks with transport text Unicode text
--set MyDoc to parse tasks with transport text theText as single task singleTask
set start date of first item of MyDoc to (current date) + 1 * days
set due date of first item of MyDoc to (current date) + 4 * days
end tell
end tell
 
Assuming that "Save some time" is an existing project, and "Library" is an existing context:

Code:
tell application id "com.omnigroup.omnifocus"
	tell default document
		set theText to "do some reading > Save some time @ Library"
		parse tasks with transport text theText
	end tell
end tell
(No need to store the result in a variable unless you need to do something with it).

--

Last edited by RobTrew; 2010-10-10 at 10:21 AM..
 
Quote:
Originally Posted by roontoon View Post
set theText to parse tasks with transport text Unicode text
--set MyDoc to parse tasks with transport text theText as single task singleTask
set start date of first item of MyDoc to (current date) + 1 * days
set due date of first item of MyDoc to (current date) + 4 * days
end tell
end tell
Uh, yeah, "unicode text" is a description of what is supposed to go there :)

so

Code:
parse tasks with transport text "draft plans > Build giant robot @ Lair of doom #today #+3d" as single task true
would create an action called "draft plans" in project "Build giant robot" with context "Lair of doom" with a start date of today and a due date of 3 days from now, and the "as single task true" bit is only needed if you had a multiple line entry that you wanted parsed as a single action.

I tried to suggest this in the original "a bit of advice" thread, but I also showed you what was wrong with your code and I fear I distracted you from this course, sorry about that.
 
Quote:
Originally Posted by RobTrew View Post
(Might be worth a suggestion to Help > Support that it could usefully be included in the main help file)
It already is there, see help topic "Processing Mail messages into actions".
 
Quote:
Originally Posted by RobTrew View Post
set theText to "do some reading > Save some time @ Library"
Thank you for your response, and yes I have done MUCH reading both on the net and here and the OmniFocus applescript dictionary. While scripting may come easy to you for many including myself it is sometimes a struggle so your remark above was pretty much unwarranted. While it is very apparent that you are very knowledgeable with OF and apple scripting it is not apparent why you would want to diminish someone who is trying to learn something that you have mastered. Remember to teach is to be humble and patient. If you have a problem with me or my question that escapes me as to what it would be.

But as I have said in my last post the script I have so far does everything I want except enter the project and context. The reason something like set (project name of theTask) to newprojectName does not work escapes me.
It also pretty apparent that Omni needs to create a suite of scripts that demonstrates how scripting in all of it's facets works with OmniFocus.

d :confused:
 
Quote:
Originally Posted by whpalmer4 View Post
Uh, yeah, "unicode text" is a description of what is supposed to go there :)
so using

set theText to parse tasks with transport text Unicode text

the above command should or shouldn't work if the text I am parsing is in the format you stated below?

Code:
parse tasks with transport text "draft plans > Build giant robot @ Lair of doom #today #+3d" as single task true

Quote:
I tried to suggest this in the original "a bit of advice" thread, but I also showed you what was wrong with your code and I fear I distracted you from this course, sorry about that.
I focused on your second example not your first. I did not relize until this thread that the orgin of the text being parsed didn't matter.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding actions for a context but getting the wrong project gokubi OmniFocus for iPhone 3 2011-07-07 06:56 AM
Adding start date to project removes actions from Context view HSstudio OmniFocus 1 for Mac 5 2010-07-19 03:46 PM
Adding item with no context wmeleis@westernfog.com OmniFocus for iPhone 8 2009-03-29 10:02 AM
Adding New Context on 1.1 denrael OmniFocus 1 for Mac 6 2008-08-04 12:45 PM
Adding Sub-Context by typing gotung OmniFocus 1 for Mac 2 2008-08-04 08:22 AM


All times are GMT -8. The time now is 01:16 PM.


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