Weeknotes for the week ending Jun.17
17 Jun 2022
Hazel.app is an outstanding utility – one I’ve written about before – for watching directories and doing something based on when things changed, certain criteria, etc. The lightest lift is something like “move all screenshots in my Desktop to the trash after a month”, yadda yadda.
I host this blog on Netlify, but new images are being served by an instance of imgproxy
that grabs them from an s3 bucket. All new photos that I add to my local “photos” directory I also want sent up to that S3 bucket. Until now it’s been a process of manually copying those files to the bucket.
Well, that’s boring.
How can I set things up to just automatically do it?
- Install s3cmd
- Set it up with
s3cmd --configure
. Save the config to the default location which is~/.s3cfg
- Test it out:
s3cmd put /path/to/local/file.jpg s3://your-bucket/some/existing/directory/
(it should work) - If you’re using Hazel, at this point you can drag the directory you’re watching to the “Folders” pane on the left.
-
Create a new rule that looks something similar to:
If all of the following conditions are met:
Extension is jpg
Do the following to the matched file or folder:
Run shell script, embedded script, (i) Edit Script
-
Click that “Edit Script” and make it look like:
/opt/homebrew/bin/s3cmd --config=~/.s3cfg put $1 s3://your-bucket/your/target/path/
- Open up the Hazel logs to make sure things worked:
Help -> View Logs