[Users] Action to integrate Claws with Taskwarrior

Milan Obuch claws-mail-users at dino.sk
Mon Jul 12 13:10:56 CEST 2021


On Mon, 12 Jul 2021 10:41:07 +0200, Saša Janiška <gour at atmarama.com>
wrote:

> Hello,
> 
> a the moment I'm using simple shell script to be able to integrate
> with Taskwarrior so that I can create new tasks from Claws by using
> Actions feature.
> 
> Currently, the action is as follows:
> 
> grep "^Subject:\ " %f | cut -d\  -f 2-| ~/bin/claws2tw.sh
> 
> The script is :
> 
> #!/usr/bin/sh
> 
> 
> read TEXT
> test -z "$TEXT" && \
>         exit 0
> 
> task add $TEXT +in +email
> exit $?
> 
> and the output of the script is e.g.:
> 
> --- Ended: grep "^Subject:\ "
> "/home/gour/.claws-mail/imapcache/mail-server/user-idINBOX/16321" |
> cut -d\  -f 2-| ~/bin/claws2tw.sh Created task 189.
> 
> and by clicking on Claws' toolbar, it creates a Taskwarrior task #189
> using Subject as Taskwarrior's description along with {in,email} tags.
> 
> Now, I'd like to enhance the integration so that I when I on the task 
> within Taskwarrior it can select appropriatemessage in Claws.
> 
> In order to do it, I'd have to use taskopen helper script in
> Taskwarrior, but I wonder what would be the simplest way to create &
> annotate task via custom Action which should do one additional thing
> besides current claws2tw.sh script and that is to execute:
> 
> task ann 189 -- claws-mail --
> select/home/gour/.claws-mail/imapcache/mail-server/user-idINBOX/16321
> 
> so that I can use 'taskopen 189 -x' and invoke Claws-mail selecting
> desiring message?
> 
> Do you recommend to do it with enhanced shell script, using Python
> plugin or something?
> 

Hi,

I have no experience with Task Warrior, I just installed it now out of
curiosity. So, let me reiterate what you wrote and comment...

First, with selected mail, invoking action, you create a new task with
mail's subject becoming task's description. Fine.

Now, what would you like to do, requires saving output of task's
invocation to some variable - you need new task's id. This could be
achieved easily using shells backtics operator (off my head without
consulting man sh, something like

id=`task add $TEXT +in +email`

should do just this, but check syntax carefully, I may be wrong in
some detail). I would probably recommend quoting $TEXT as "$TEXT" or
something similar as subject in received mail can contain spaces or any
other chars, potentially confusing shell's parser.

With that id in a variable, you can then add another task's invocation
in the same claws2tw.sh script before exit$? line, something like

task ann $id -- claws-mail --select $1

which should do just what you'd like to, assuming you modify your
action

grep "^Subject:\ " %f | cut -d\  -f 2-| ~/bin/claws2tw.sh

to

grep "^Subject:\ " %f | cut -d\  -f 2-| ~/bin/claws2tw.sh "%f"

Maybe this way you are basically done. I did not find 'taskopen' after
installing TaskWarrion port to my FreeBSD workstation so no comment on
that one, no idea what it does.

So my recommendation after writing this is try what I wrote and
evaluate it, it could fullfill your needs according your mail. It is by
far not perfect, I'd move grep and cur into shell script, so action
invocation would be just

~/bin/claws2tw.sh "%f"

and everything should be done inside the script.

Some time ago I would recommend using Python plugin if you like (or at
least are able to) write scripts in Python. It is good tool for
creating more complicated tasks well integrated into Claws Mail's
framework.

As I was not able to build Python plugin for some period of time on my
workstation and I missed its functionality, after some tests I decided
to create another scripting plugin based on Lua. It turned out to be
surprisingly easy for me, using some concepts and functions from other
plugins, so I stick for now with it and if I'd like to do something
similar, I'd use Lua plugin. It is not (yet) part of official Claws
Mail's source tree, but I made it available via devel mailing list. You
need to build it yourself if you'd like to try it, but it is easy, as I
wrote in some mails to devel list.

It's your turn now. Try, evaluate, think and let us know your decision
- ask a question if necessary.

Best regards,
Milan


More information about the Users mailing list