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

 
Applescript Duplicate command: how to use it? Thread Tools Search this Thread Display Modes
Hi,

I would need some help to use the duplicate command to duplicate a single task.

Here is what I got so far:
The [...] is the not relevant code that has been stripped out

Code:
property WForContext : "WFor"

tell application "OmniFocus"
	-- [...]
	tell front document
		tell document window 1
			set theSelectedItems to selected trees of content
		end tell
	end tell
	
	set theSelectedTask to value of item 1 of theSelectedItems
	
	set MyDoc to first document
	tell MyDoc
		-- [...]
		set contextList to complete WForContext as context maximum matches 1
		
		-- [..]
		set theWForContext to context id (id of item 1 of contextList)
		-- PROBLEM: what is the "to" arg expecting?
		-- (Arg that is optional according to the doc, but is expected by OF - Bug filled to support Ninjas)
		
		set theResult to duplicate (theSelectedTask) to (after last task) with properties {context:theWForContext}
		
		-- [..]
		
	end tell
	-- [..]
end tell
Any help would be greatly appreciated.
 
At 'at' needs to be a fully fledge location specifier relative to the enclosing 'tell' block. Right now (at least) a 'document' doesn't really have tasks -- that the relationship exists is an implementation details to make 'id' specifiers work nicely. Sadly, there isn't a good way to document this in the suite.

With a task selected in project mode, this works for me. Of course, this will fail if you have an inbox task, project, or collation group selected. Also, you might want it to copy inside the parent task group if any, but this is a starting point =)

It looks like the 'with properties' isn't working on 'duplicate' right now. I've logged a bug on this.

Code:
tell application "OmniFocus"
	tell default document
		tell document window 1
			set theSelectedItems to selected trees of content
		end tell
		set theSelectedTask to value of item 1 of theSelectedItems
		set theResult to duplicate theSelectedTask to end of tasks of containing project of theSelectedTask with properties {context:context "cc"}
	end tell
end tell
__________________
CTO, The Omni Group
 
Thanks a lot Tim.

I will be watching the release notes for the fix.
 
The line
Code:
set theResult to duplicate theSelectedTask to end of tasks of containing project of theSelectedTask
does also not set the variable theResult.

Could you fix that? Do you prefer that I fill a formal bug report?
 
Quote:
Originally Posted by Lutin View Post
The line
Code:
set theResult to duplicate theSelectedTask to end of tasks of containing project of theSelectedTask
does also not set the variable theResult.

Could you fix that? Do you prefer that I fill a formal bug report?
Thanks! I've written this one up; <bug://bugs/42532> ('duplicate' doesn't return the result)
__________________
CTO, The Omni Group
 
These problems should be fixed in 93614.
__________________
CTO, The Omni Group
 
Thanks a lot.

My script is now working (cf. this post).
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
applescript to delete duplicate tasks jamesafoster OmniFocus Extras 1 2013-04-02 07:55 AM
reference of result of duplicate command in applescript? ericscheid OmniGraffle General 1 2012-09-05 10:25 PM
Duplicate Action (applescript request) steve OmniFocus Extras 7 2012-01-13 08:12 AM
AppleScript references with no set or command MLModel OmniOutliner 3 for Mac 1 2010-11-21 11:34 AM
duplicate the above row-- applescript? steve OmniOutliner 3 for Mac 2 2006-05-02 07:18 AM


All times are GMT -8. The time now is 01:08 AM.


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