Hazel: Log processed files via PushOver instead of an append in a text document

Hey all,

I have a bunch of nice hazel rules which processes incoming pdf files and moves them to the appropriate folder.
As I would like to have an overview which files were processed, I am looking for a solution to log the processed files and see that log on my iOS device.

I know that hazel itself has a log, but for my use case there seems to be to much not needed stuff in there, and also the log is not easily reachable form iOS.

I am wondering if it’s best to append text to a file on iCloud via Applescript / JavaScript as part of each rule. Is this going to take to much take to open the file and write the content in the file, so that the rules get screwed up? Does any one know where a sample script for this kind of task could be found?

Or perhaps an integration with Drafts could be the better way?

Thanks for your suggestions and your help.

Adding to a file in iCloud would seem the best way to have a running log on iOS.

I’d recommend using a shell script to append to the file a you can just append to it using a redirect. It’s about as fast as you’re going to get.

e.g. to append the date & time to the end of a file called mylog.log in your home directory, you could do this.

date >> ~/mylog.log

You would just want to build up what you want to write out to the file and direct it at the appropiate iCloud location.

If you just want to know when something has been processed I’d recommend using something like Pushover. I use this to notify me for several Hazel activities that I run on my Mac Mini server.

Hope that helps.

1 Like

Thank you for your input. Yes, that’s absolutely the direction i want to go to.

I did managed to create the log entry for either the time stamp or the file name:

#Works for just the file name
#file=$(basename $1)
#echo $file >> ~/mylog.log

#Works for just the time stamp
#date >> ~/mylog.log

Unfortunately it didnt’t worked for the combination of time stamp and file name:

file=$(basename $1)
output="$date $file"
echo $output >> ~/mylog.log

I assume the syntax is wrong, but couldn’t figure it out yet how to combine both.
At pushover I will gladly have a look at next.

As an embedded script, try something along these lines, but with it directing to your actual log file.

Shell: /bin/bash

echo $(date '+%Y-%m-%d-%H.%M.%S') ${1##*/} >>  ~/mylog.log

This should then poduce log entries like this.

2019-01-01-11.11.11 file_123.txt
2019-01-01-12.12.12 file_456.txt
2019-01-01-13.13.13 file_789.txt

Hope that helps.

Worked great - thank you!

Had a look at Pushover - looks very promising!

With the shell command below (adapted for publication) I was able to send a notification via mac terminal:

curl -s \
  -F "token=mytoken" \
  -F "user=myuserkey" \
  -F "message=bbb" \
  -F "device=mydevice" \

However, when embedded in a ‘Run shell script’ action in hazel (embedded script), the pushover notification isn’t triggered. Is anything missing which is additionally needed in hazel?

I don’t think so, but I have mine set to use an external script file. I have a script setup that I can call from other scripts and apps as well as Hazel that sends the message. it makes it easy to use anywhere.

I don’t have time to take a look and figure it out now (I have an early start on a business trip tomorrow), but I would recommend having that as a separate script outside of Hazel for the flexibility described above.

Thanks to sylumer, I found a much better solution for getting an overview which hazel rules fired than a plain log file.

The solution via PushOver is far superior.
The shell scirpt for the PushOver API call is now embeded as external file in hazel.
This is the code i used:

#!/bin/sh -e
curl -s \
-F "token=MyToken" \
-F "user=MyUser" \
-F "title=${1##*/}" \
-F "message=$(date '+%Y-%m-%d-%H.%M.%S'):
" \
-F "device=MyDevice" \

The line breaks (according to PushOver FAQ) take care of separate lines in the send notification.
If you have further tune suggestions, please let me know.