How to create a task and then an annotation in a script?

32 views
Skip to first unread message

Manfred Lotz

unread,
Jun 17, 2019, 3:21:34 PM6/17/19
to taskwarrior-dev
In a script I want to create a task and then an annotation to the just created task. For the annoatation I need the task number.

How can I do this?

-Gary-

unread,
Jun 17, 2019, 4:47:31 PM6/17/19
to taskwar...@googlegroups.com
Manfred,

The development alias is probably not the best for this.

However, one quick answer is the "ids" command. In my scripts, I do this:

task rc.verbose=nothing ids | sed "s/^1[-]//g"

It returns the IDs matching a filter, and without a filter just returns the entire range. Since the newly created task is the newest one, then the last ID is it.

Be advised that this will only work for serial scripts. Any parallel processing will create a race condition, since the tasks file may be modified by another process between the creation and ID check of the first process. In that case, you may do something like:

task rc.verbose=new-uuid add [...]

You can then parse the result of this command. Note that the "taskrc" man page says that the "new-uuid" command is deprecated and will be merged with "new-id", so you will have to update your script at some future version.

I hope this helps.

-- Gary


------------------------------
> Date: Mon, 17 Jun 2019 12:21:34 -0700 (PDT)
> From: Manfred Lotz <being.a...@gmail.com>
> To: taskwarrior-dev <taskwar...@googlegroups.com>
> Subject: [taskwarrior-dev] How to create a task and then an annotation in a
> script?
>
> In a script I want to create a task and then an annotation to the just created task. For the annoatation I need the task number.
>
> How can I do this?
>
> --
> You received this message because you are subscribed to the Google Groups "taskwarrior-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to taskwarrior-d...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/taskwarrior-dev/3bc8f088-9fb6-4946-bb23-bf64392f4e87%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Tomas Babej

unread,
Jun 17, 2019, 8:16:12 PM6/17/19
to taskwar...@googlegroups.com
You can also simply do

$ task add my task
$ task +LATEST annotate my annotation

Cheers,
Tomas

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, June 17, 2019 4:47 PM, -Gary- <m...@garybgenett.net> wrote:

> Manfred,
>
> The development alias is probably not the best for this.
>
> However, one quick answer is the "ids" command. In my scripts, I do this:
>
> task rc.verbose=nothing ids | sed "s/^1[-]//g"
>
> It returns the IDs matching a filter, and without a filter just returns the entire range. Since the newly created task is the newest one, then the last ID is it.
>
> Be advised that this will only work for serial scripts. Any parallel processing will create a race condition, since the tasks file may be modified by another process between the creation and ID check of the first process. In that case, you may do something like:
>
> task rc.verbose=new-uuid add [...]
>
> You can then parse the result of this command. Note that the "taskrc" man page says that the "new-uuid" command is deprecated and will be merged with "new-id", so you will have to update your script at some future version.
>
> I hope this helps.
>
> -- Gary
>
>
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> > Date: Mon, 17 Jun 2019 12:21:34 -0700 (PDT)
> > From: Manfred Lotz being.a...@gmail.com
> > To: taskwarrior-dev taskwar...@googlegroups.com
> > Subject: [taskwarrior-dev] How to create a task and then an annotation in a
> > script?
> > In a script I want to create a task and then an annotation to the just created task. For the annoatation I need the task number.
> > How can I do this?
> > --
> > You received this message because you are subscribed to the Google Groups "taskwarrior-dev" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to taskwarrior-d...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/taskwarrior-dev/3bc8f088-9fb6-4946-bb23-bf64392f4e87%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
>
> You received this message because you are subscribed to the Google Groups "taskwarrior-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to taskwarrior-d...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/taskwarrior-dev/20190617204725.GB27908%40spider.

Scott Kostyshak

unread,
Jun 18, 2019, 9:36:06 PM6/18/19
to taskwar...@googlegroups.com
On Mon, Jun 17, 2019 at 12:21:34PM -0700, Manfred Lotz wrote:
> In a script I want to create a task and then an annotation to the just created task. For the annoatation I need the task number.
>
> How can I do this?

Another possibility might be to use Taskwarrior's JSON import. I haven't
tried this though so I'm not sure.

Scott

Manfred Lotz

unread,
Jun 19, 2019, 1:40:26 PM6/19/19
to taskwarrior-dev

First of all thanks to all for your answers.

On Tuesday, June 18, 2019 at 2:16:12 AM UTC+2, Tomas Babej wrote:
> You can also simply do
>
> $ task add my task
> $ task +LATEST annotate my annotation
>

But this is just superb. Thanks again.

--
Manfred


Reply all
Reply to author
Forward
0 new messages