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 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.
things.sh today is the command to pull the to-dos for today.
The terminal result is kind of ugly:
(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:
/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.
Because of the way that Hazel runs the script, the $HOME variable is not set. In a typical shell environment it would be set to your user’s home directory /Users/yourusername. Try adding
export HOME=/Users/yourusername
as the first line of the script run by Hazel to solve that error at least.
I appreciate everyone taking time to add their input.
Sadly there is a significant limitation to this plan that I didn’t realize. Things 3 on the Mac appears to update the application’s database from Things Cloud whilst the app is active.
I noticed to-dos I added on iOS where not updated in Things and therefore did not appear on the text file via Hazel.
Well, it was a good idea and the Hazel bit works thanks to the input on this forum.