The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Applescript Duplicate command: how to use it? (http://forums.omnigroup.com/showthread.php?t=5284)

Lutin 2007-10-25 01:51 AM

Applescript Duplicate command: how to use it?
 
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
[/code]

Any help would be greatly appreciated.

Tim Wood 2007-10-25 10:59 PM

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

Lutin 2007-10-26 02:21 AM

Thanks a lot Tim.

I will be watching the release notes for the fix.

Lutin 2007-10-26 03:00 AM

The line [code]set theResult to duplicate theSelectedTask to end of tasks of containing project of theSelectedTask[/code] does also not set the variable theResult.

Could you fix that? Do you prefer that I fill a formal bug report?

Tim Wood 2007-10-26 07:38 AM

[QUOTE=Lutin;23449]The line [code]set theResult to duplicate theSelectedTask to end of tasks of containing project of theSelectedTask[/code] does also not set the variable theResult.

Could you fix that? Do you prefer that I fill a formal bug report?[/QUOTE]

Thanks! I've written this one up; <bug://bugs/42532> ('duplicate' doesn't return the result)

Tim Wood 2007-10-29 07:23 PM

These problems should be fixed in 93614.

Lutin 2007-10-30 12:56 AM

Thanks a lot.

My script is now working (cf. [URL=http://forums.omnigroup.com/showthread.php?p=23705#post23705]this post[/URL]).


All times are GMT -8. The time now is 08:35 PM.

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