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 Search Today's Posts Mark Forums Read

 
Need help creating a script for creating a next action Thread Tools Search this Thread Display Modes
I could greatly use some help creating a script that would be a nice addition to my work flow. The use case is during my morning review an next action will appear and I realize that I have to do something before that. I want to write a script that will take the project name from the highlited task, presents a dialog asking me for a new task name and then creates a new task assigned to that project. The key though is I want that new task to be the next action. So I guess I need to make sure then when adding to the task is inserts it at the begining of the avalabile tasks within the project. Not at the end like Quick Entry does. Can anyone script this out to give me a starting point?

Thanks a bunch in advance,

George

Last edited by gcrump; 2009-01-28 at 08:57 AM..
 
George,

That's a tricky problem. What should happen if the selected task is nested within action groups? Do you want the script to "climb" all the way up to the project and add a new first task at that level?
__________________
Cheers,

Curt
 
Was planning on the task being the top level, I don't do a lot of nesting. Does that help?
 
Quote:
Originally Posted by curt.clifton View Post
George,

That's a tricky problem. What should happen if the selected task is nested within action groups? Do you want the script to "climb" all the way up to the project and add a new first task at that level?
Curt, isn't the matter simplified a bit by the fact that it was already known to be a next action? Seems like "make new task in front of current_task" or the equivalent would work, no?
 
Where I am struggling with this script is in two areas, first is in setting the context. In a subsequent dialog I prompt for the context. I have seen the complete context code but can't seem to figure out how to get it to work.

If I can figure that part out I was thinking the code for creating the task would be something like...

Code:
set theSelectedTask to value of item 1 of theSelectedItems
set newTask to make new task with properties {name:theTaskName, context:theContext}
set assigned container of newTask to theProject
move newTask to before task 1 of theProject
Which all compiles OK, not sure if it will work until I figure out how to set the context.

Here is the complete code such that it is
Code:
tell application "OmniFocus"
	tell front document
		tell (first document window whose index is 1)
			set theSelectedItems to selected trees of content
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select a single task." message "Select a single task before running this script." as warning
				return
			end if
			if ((count of theSelectedItems) > 1) then
				display alert "You must select only one task." message "Select a single task before running this script." as warning
				return
			end if
			
			display dialog "Enter the new next action for this project" buttons {"Cancel", "Add"} default button 2 default answer "" with title "New Next Action"
			if button returned of result is "Add" then
				set theTaskName to text returned of result
				display dialog "Enter the context" buttons {"Cancel", "Add"} default button 2 default answer "" with title "New Context"
				if button returned of result is "Add" then
					set newContext to text returned of result
				end if
				
				set MyContextList to complete newContext as context maximum matches 1
				set MyContextID to id of first item of MyContextList
				set theContext to context id MyContextID
				
				
				set theSelectedTask to value of item 1 of theSelectedItems
				set theProject to the name of the containing project of theSelectedTask
				set newTask to make new task with properties {name:theTaskName, context:theContext}
				set assigned container of newTask to theProject
				move newTask to before task 1 of theProject
			end if
		end tell
	end tell
end tell
The error I am getting now is in the line
set MyContextList to complete newContext as context maximum matches 1

and the error is OmniFocus got an error: "email" doesn’t understand the complete message. "email" was the value of new Context.

As you can see any help would be appreciated.

Thanks,

George

Last edited by gcrump; 2009-01-29 at 03:00 AM..
 
George tagged me into the ring to help on this one.

Here's what I came up with, complete with LaunchBar integration to avoid the extra song and dance of the dialog. It also selects the new task on completion to make it easy to add context and whatnot to it.

Code:
on handle_string(s)
	of_followup(s)
end handle_string

on run
	of_followup("")
end run


on of_followup(taskname)
	tell application "OmniFocus" to tell document 1
		tell content of document window 1 to get value of descendant trees whose selected is true
		set selectedItems to result
		-- put a repeat here once it's troubleshot
		set xItem to item 1 of result
		get class of item 1 of result
		if result is task then
			set theProject to containing project of xItem
			set theContext to context of xItem
			if taskname is "" then
				display dialog "New task name is...?" default answer "Copy of " & (name of xItem)
				set taskname to text returned of result
			end if
			make new task at beginning of tasks of theProject with properties {name:taskname} --, context:(context of xItem)}
			set newTask to result
			tell content of document window 1 to select {newTask}
		else
			beep
		end if
	end tell
end of_followup
 
Quote:
Originally Posted by whpalmer4 View Post
Curt, isn't the matter simplified a bit by the fact that it was already known to be a next action? Seems like "make new task in front of current_task" or the equivalent would work, no?
Looks like Nik has stepped in with a solution, but at the risk of going off-topic...

I was trying to see if there is a more general problem/solution here. Rather than coding for the special case of having the next action selected, I was thinking about having any action selected, then adding a new action at the top of the project/group. Why solve one problem when you can solve several at a time!
__________________
Cheers,

Curt
 
True enough, but I'm sure you'll agree there are plenty of problems resistant to solution in a general form, but nonetheless quite usefully solved for limited cases :)
 
Nik, Thanks for the assist. That works real well.
 
This is a great script but I'm having a problem with it. When I'm in a perspective that the next action doesn't appear in, the script fails saying that it can't find the object to select. I guess I should be in a review context or something, but it might be good to have it work wherever you are.

Also, I was wondering if there is any way to add the context in a dialog. It would be nice for my situation where the action doesn't show up.

Thanks again for the script!
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Links to Files : is there a script? Simon Knight OmniGraffle General 5 2012-01-14 12:18 PM
Creating a dated OF action with links to DevonThink record(s) RobTrew OmniFocus Extras 0 2011-02-13 01:21 PM
Creating New Action in Project ignored gWaldo OmniFocus for iPhone 2 2010-09-01 03:59 PM
Creating action groups within a project atreinke OmniFocus for iPhone 5 2010-07-02 12:47 PM
odd behavior creating a action in Context view wfiveash OmniFocus 1 for Mac 3 2007-12-16 09:34 PM


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


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