Page 1 of 1

Implement Things CLI Rule with Shell Script

PostPosted: Fri Jun 28, 2019 6:04 pm
by biznachio
Hello all,

I'm seeking some assistance implementing a shell script in Hazel. I've reached the limit of my current abilities, and I humbly ask for help.

Quick back story. I found Things CLI, https://github.com/AlexanderWillner/things.sh, which is a handy shell script that peeks into Things SQLite database. I use it to turn to-dos into text and then manipulate the result.

What I'm hoping to achieve is to have Hazel watch the Things.sqlite3 file. When the database is modified, I'm trying to run this shell script.
Code: Select all
/usr/local/bin/things.sh today | cut -d '|' -f 2 | tr -d '' > "/Volumes/Olgeird/Dropbox/Apps/Things.txt"

things.sh today is the command to pull the to-dos for today.

The terminal result is kind of ugly:
Code: Select all
(No Context)|New on Mac|things:///show?id=58E7BFD1-7614-43B5-BC93-DA75992BE49D

So I'm using cut and tr to extract the to-do name and write the result to a text file in Dropbox.

I've had mixed results with the script in Hazel. The script runs occasionally but does not write any text to the text file. More often the shell script errors. In the log I see:
Code: Select all
/usr/local/bin/things.sh: line 70: HOME: unbound variable

I'm unsure what this means or how to fix it. I'm open to suggestions and guidance from the community.

Thanks all. I really appreciate you taking time to help.

~James

Re: Implement Things CLI Rule with Shell Script

PostPosted: Sat Jun 29, 2019 8:33 pm
by luomat
I've had mixed results with the script in Hazel. The script runs occasionally but does not write any text to the text file. More often the shell script errors. In the log I see:

/usr/local/bin/things.sh: line 70: HOME: unbound variable

I'm unsure what this means or how to fix it. I'm open to suggestions and guidance from the community.


Looking at https://github.com/AlexanderWillner/things.sh/blob/master/things.sh I can see that this is line 70:

Code: Select all
export EVENTLIST="$HOME/.trip.thingslist"


"$HOME" is a very basic variable in shell scripts, so I am very surprised that 'things.sh' isn't able to figure out what it is, but it also suggests that the reason the script isn't working in Hazel is because it's not inheriting the "environment" properly. However, I am not sure _why_ it is not inheriting the environment.

Re: Implement Things CLI Rule with Shell Script

PostPosted: Mon Jul 01, 2019 9:22 am
by Mr_Noodle
I would expect $HOME to be set as well but I guess not. Try using ~ instead.

EDIT: To clarify, precede the script with "export HOME=~" and see if that fixes it.