The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   AppleScripting Omni Apps (http://forums.omnigroup.com/forumdisplay.php?f=46)
-   -   Adding Project and Context (http://forums.omnigroup.com/showthread.php?t=18447)

roontoon 2010-10-09 01:36 PM

Adding Project and Context
 
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

[/CODE]

RobTrew 2010-10-10 01:50 AM

In the OmniFocus app:

Help > Release Notes > Archive (a [URL="file:///Applications/OmniFocus.app/Contents/Resources/MessageOfTheDayArchive.html"]link[/URL] 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)

[COLOR="White"]--[/COLOR]

roontoon 2010-10-10 06:15 AM

[QUOTE=RobTrew;87154]In the OmniFocus app:

Help > Release Notes > Archive (a [URL="file:///Applications/OmniFocus.app/Contents/Resources/MessageOfTheDayArchive.html"]link[/URL] 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)

[COLOR="White"]--[/COLOR][/QUOTE]


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[/CODE]

RobTrew 2010-10-10 09:22 AM

[QUOTE=roontoon;87160]it looked to me to be info on parsing from an email to OF[/QUOTE]

[B]set[/B] [I]theResult[/I] [B]to parse tasks with transport text[/B] [I][COLOR="Blue"]unicode text[/COLOR][/I]

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

[B]-- Action > Project @ Context[/B]

If your [I][COLOR="Blue"]theText[/COLOR][/I] variable only contains the name of the action, you simply need to append the name of a project, preceded by [B]>[/B] 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.

[COLOR="White"]--[/COLOR]

roontoon 2010-10-10 10:31 AM

[QUOTE=RobTrew;87166][B]set[/B] [I]theResult[/I] [B]to parse tasks with transport text[/B] [I][COLOR="Blue"]unicode text[/COLOR][/I]

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

[B]-- Action > Project @ Context[/B]

If your [I][COLOR="Blue"]theText[/COLOR][/I] variable only contains the name of the action, you simply need to append the name of a project, preceded by [B]>[/B] 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.

[COLOR="White"]--[/COLOR][/QUOTE]


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
[COLOR="Red"]set theText to theText & ">" & defaultProject[/COLOR]
tell application "OmniFocus"
set MyDoc to default document
tell application "OmniFocus" to tell MyDoc
set singleTask to true
[COLOR="Red"]set theText to parse tasks with transport text Unicode text[/COLOR]
--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

RobTrew 2010-10-10 11:11 AM

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[/CODE]

(No need to store the result in a variable unless you need to do something with it).

[COLOR="White"]--[/COLOR]

whpalmer4 2010-10-10 11:26 AM

[QUOTE=roontoon;87167]
[COLOR="Red"]set theText to parse tasks with transport text Unicode text[/COLOR]
--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[/QUOTE]
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
[/code]
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.

whpalmer4 2010-10-10 11:37 AM

[QUOTE=RobTrew;87154]
(Might be worth a suggestion to Help > Support that it could usefully be included in the main help file)
[/QUOTE]

It already is there, see help topic "Processing Mail messages into actions".

roontoon 2010-10-10 11:58 AM

[QUOTE=RobTrew;87174]
set theText to "do some reading > Save some time @ Library"
[/QUOTE]

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:

roontoon 2010-10-10 12:08 PM

[QUOTE=whpalmer4;87176]Uh, yeah, "unicode text" is a description of what is supposed to go there :)
[/quote]

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
[/code]


[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.[/QUOTE]

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.


All times are GMT -8. The time now is 04:12 PM.

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