Implement Things CLI Rule with Shell Script

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Implement Things CLI Rule with Shell Script 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
biznachio
 
Posts: 2
Joined: Sat Aug 04, 2018 6:42 am

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.
luomat
 
Posts: 78
Joined: Wed Mar 10, 2010 3:57 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support