The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Populate Template Placeholders, 0.6.1 (http://forums.omnigroup.com/showthread.php?t=12870)

curt.clifton 2009-06-25 12:15 PM

Populate Template Placeholders, 0.6.1
 
I've posted an updated version of my Populate Template Placeholders script to [URL="http://www.rose-hulman.edu/~clifton/software.html"]my software page[/URL]. Here's a description of the script lifted from there:

[QUOTE]
Templates were the only thing missing in the current version of OmniFocus that were part of my old GTD system. But the scripting interface in OmniFocus is solid enough to implement them!

Here is a script that will take an OmniFocus project, replace placeholders with user entered strings, and adjust all dates by some fixed interval-again based on user input. Installation and use instructions are included in the download.

The latest version can handle apostrophes and other punctuation inside the replacement text. It’s also faster and has a shiny new icon so it’s spiffy on your tool bar.
[/QUOTE]

Share and enjoy!

jeremydb 2009-06-26 06:53 AM

Hi Curt -

Thanks for your script. Unfortunately, I get an error when I run it. The line "duplicate (value of item 1 of theSelectedItems) to after last section" throws the following error (translated from German):

Objects of the class "task" cannot be put after <Document: 0xWHATEVER>. scriptSections requires "section".

Any ideas?

Thanks, Jeremy

curt.clifton 2009-06-26 08:41 AM

Sorry for the confusion. You need to select a Project to be populated, not an Action. I'll add code to check for that to a future version of the script.

Edit: I’ve posted that update. Version 0.6.2 is now available.

jeremydb 2009-06-26 09:23 AM

I actually modified your script to work with actions, as well, and to not require subsitutions, if all you want is to dupe the project to some other time, changing the dates. There is a bug in OF's handling of repeating actions containing nested actions, so this script seems to be a way around it. I can send you the mods, if you want them.

curt.clifton 2009-06-26 09:40 AM

I'm glad the script provided a useful starting point. Feel free to post the mods here so others can use them.

BwanaZulia 2009-06-26 11:30 AM

Great script. Been using it forever. Would love for OG to put this in the product, but it has been working so long, I guess it is all good.

BZ

kingsinger 2009-07-01 03:04 PM

Bug in ver .70?
 
Apologies if this isn't the right place to raise this.

I downloaded version .7 and when I tried to use it I got the following error

AppleScript reported the following error:
OmniFocus got an error: Can’t get name of value of tree 1 of content of document window id 14081 of document id "iAF1BObmx-F".

curt.clifton 2009-07-01 04:31 PM

Odd, I've never seen that particular error. What steps do you have to take to reproduce the error? What versions of OF and the operating system are you using?

RobTrew 2009-07-02 09:21 AM

[QUOTE=kingsinger;62099]AppleScript reported the following error:
OmniFocus got an error: Can’t get name of value of tree 1 of content of document window id 14081 of document id "iAF1BObmx-F".[/QUOTE]

Glancing at the script, I would guess that it's just an unhandled selection.

Try, for example, to run it while selecting the "No Context" icon in the content pane or sidebar of Context view (or the Inbox icon in the content pane or sidebar of Project view): it would probably trigger an error of this kind. (These nodes don't have name properties).

Rob

curt.clifton 2009-07-02 10:37 AM

Thanks, Rob. Interestingly, those nodes have name properties, but if you take the name [I]of the value[/I] of such a node you get an error.

That gave me a better way to do my checks for correct selections. Version 0.7.1 is now available from [URL="http://www.rose-hulman.edu/~clifton/software.html"]my software page[/URL].

RobTrew 2009-07-02 11:17 AM

[QUOTE=curt.clifton;62141]those nodes have name properties, but if you take the name [I]of the value[/I] of such a node you get an error.[/QUOTE]

A helpful distinction - I hadn't noticed.

Odd that the value fails to pass that property through - Bug ?

curt.clifton 2009-07-02 12:22 PM

Not sure if this is a bug or just an inconsistency. Here's a script that demonstrates the issues (which I'll also send to the ninjas):

[CODE]
(*
Run this script with one of the built-in sidebar items selected (e.g. No Context
or Context in context mode, or Inbox or Library in planning mode). The fourth
set will yield an error. Run it again with a project, context, or folder selected
and everything is fine.

In the first case, bar is set to something like:
value of tree 2 of sidebar of document window id 60308 of document id "jwv2Yzh3ZwG"

In the second case, bar is set to something like:
project id "o-8rLx0w-T7" of document id "jwv2Yzh3ZwG"

(To see this, run the script from Script Editor with the Event Log showing.)
*)
tell application "OmniFocus"
tell document 1
tell document window 1
set foo to item 1 of selected trees of sidebar
set bar to value of foo
set blah to name of foo
set baz to name of bar -- unexpected error
end tell
end tell
end tell
[/CODE]

There seem to be a couple of issues. The sidebar in planning mode has properties "library" and "inbox", which return objects of class "library tree" and "inbox tree" respectively. These classes are subclasses of "tree", which has a "value" property. But it's unclear what "value" should return for these. Perhaps just the tree itself again?

Another inconsistency is that the sidebar in context mode doesn't have properties for No Context and Contexts, which it seems like it might in analogy with planning mode.

henri 2009-12-06 12:08 PM

How would I modify the script so that the new project appears in the same folder as the template? For me it would be very helpful to set things up this way, because I'd like to keep the templates in the appropriate folders, (instead of putting them in a template folder).

Thanks in advance.

--Henri

curt.clifton 2009-12-06 01:42 PM

[QUOTE=henri;70507]How would I modify the script so that the new project appears in the same folder as the template? For me it would be very helpful to set things up this way, because I'd like to keep the templates in the appropriate folders, (instead of putting them in a template folder).[/QUOTE]

You would have to modify these two lines (from version 0.7.1 on [URL="http://www.rose-hulman.edu/~clifton/software.html"]my software page[/URL]):
[CODE]
duplicate (value of item 1 of theSelectedItems) to after last section
set duplicatedItem to last section
[/CODE]

Change the first line to specify the location of the duplicate relative to item 1 of theSelectedItems, which is the project being duplicated. Change the second line to capture a reference to the duplicate.

henri 2009-12-06 08:12 PM

[QUOTE=curt.clifton;70510]You would have to modify these two lines (from version 0.7.1 on [URL="http://www.rose-hulman.edu/%7Eclifton/software.html"]my software page[/URL]):
[CODE]
duplicate (value of item 1 of theSelectedItems) to after last section
set duplicatedItem to last section
[/CODE]Change the first line to specify the location of the duplicate relative to item 1 of theSelectedItems, which is the project being duplicated. Change the second line to capture a reference to the duplicate.[/QUOTE]

I'm afraid I need more help. I don't know enough AppleScript to know what to put after the "to"s...

--Henri

henri 2009-12-07 06:31 AM

Here is what I tried. It seems the first line works, but the second doesn't:

[code]
duplicate (value of item 1 of theSelectedItems) to after selectedItem
set duplicatedItem to item after selectedItem
[/code]--Henri

curt.clifton 2009-12-07 05:02 PM

Henri,

I'd have to implement it myself to get the second line exactly, and I'm afraid time doesn't permit that right now. You might try something like:

[CODE]
set duplicatedItem to item 1 of following siblings of selectedItem
[/CODE]

Good luck!

Cheers,

Curt

henri 2009-12-07 08:41 PM

Success! It turned out to be easier than I thought, once inspiration struck:

[code] set duplicatedItem to selectedItem [/code]

Once the item is duplicated, I can use the original as the duplicate, if you know what I mean.

Anyway, this is an awesome script! It saves a lot of work entering dates. Thank you so much.

--Henri

curt.clifton 2009-12-08 02:55 PM

Doh! <slapsHead />

Very elegant. Nicely done.

Cheers,

Curt

henri 2009-12-19 06:15 AM

One more refinement to this super-useful script: anyone (Curt?) know how to change the review frequency of a project via scripting? As it stands now, my defaults are to review templates every three months, and projects every three weeks. I'd love to change that property of a project accordingly after I've created it with this script.

whpalmer4 2009-12-19 07:20 AM

Henri, the middle section of the following code fragment shows how you can set those values.

[code]
tell application "OmniFocus"
tell front document
tell document window 1
set theSelectedItems to selected trees of content
set selectedItem to value of item 1 of theSelectedItems


-- set next review date to tomorrow
set next review date of selectedItem to (current date) + (1 * days)
-- set review interval to 3 weeks
set reviewInterval to {fixed:true, unit:week, steps:3}
set review interval of selectedItem to reviewInterval


end tell
end tell
end tell
[/code]

henri 2009-12-20 09:30 AM

Awesome! Thank you.

--Henri

bcap 2011-02-03 05:56 AM

Question everyone ...

I followed the instructions, and I can get it to duplicate a project, but it isn't replacing the placeholder text nor changing the date for me. I am getting the prompt for the new "Due Date" and for the "ClientName" (what my placeholder text is), but it won't fill it in for me.

Any ideas?

whpalmer4 2011-02-03 10:01 AM

Can you post a screenshot of your template, making sure to show the notes field for the template and the start and due date columns?

If you don't spell the placeholder exactly the same in the notes field and where you use it, no substitution will be made, and no warning given.

Did you heed the following line in the instructions?[indent]
Note, the project must have a start or due date (or both) or the script will not set dates on the actions.
[/indent]

skillet 2011-10-08 11:38 AM

If you already have a list you have been using in a text document Rob Trew's script is a nice quick start to transferring the info to OmniFocus through cut and paste.

[url]http://forums.omnigroup.com/showthread.php?t=4883[/url]

Great script Curt, I finally got around to using this to set up some templates. Thanks for the screen shot in your instructions, I didn't realize you could put comments on a project but makes sense.

By the way from the instructions it mentions
"With OmniFocus running, hold down the Option key and select the Populate Template Placeholders script from the script menu. The script should open in Script Editor."

This didn't work for me did OmniFocus get rid of this feature?

whpalmer4 2011-10-08 12:36 PM

Still works for me in 10.6.8 with OF 1.9.3.

skillet 2011-10-10 12:25 PM

Thanks whpalmer4, that is the same set up I have on my systems, I tried this on three computers as well and closed ever background and foreground app I had open and it still didn't work for me. Strange, I am clicking an script in the toolbar while holding down option and it just runs the script.

Others strange things on one of my home computer it doesn't let me use one of my key commands for a perspective. I have checked my system keyboard shortcuts and nothing uses it and no other app or background app is open that I know of. I wish I could get the ghost out and knew of a way to track things like that down, because that doesn't make sense.

whpalmer4 2011-10-11 10:44 AM

[QUOTE=skillet;102646]I am clicking an script [b]in the toolbar[/b] while holding down option and it just runs the script. [/quote]
There's your problem, this works when you select the script from the Script menu, not the toolbar. The devil's in the details :-)

skillet 2011-10-14 07:21 AM

[QUOTE=whpalmer4;102707]There's your problem, this works when you select the script from the Script menu, not the toolbar. The devil's in the details :-)[/QUOTE]


Thanks Bill, I figured it was something silly, I completely forgot that the applications scripts now show up in the scripts menu (I've had that set up for a couple years now). I was remembering the old way where it would show up next to the App menus at the far right if you had added any for a particular app.

Just a reference for anyone else that has my problem see post one.
[url]http://forums.omnigroup.com/showthread.php?t=7453[/url]


All times are GMT -8. The time now is 07:44 PM.

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