Page 1 of 1

Check something and write to a file

PostPosted: Sat Apr 15, 2017 9:18 pm
by givens
I am interested in a Hazel rule doing two things:

(1) checking if a file is above a certain size.
(2) if true, write the path and filename to a file.

Let's call the file big_file.txt. It would contain a list of filenames that are big.

Doing part (2) in Hazel is what I'd like help with.

One could write a script, but I am not sure how to start.

Re: Check something and write to a file

PostPosted: Mon Apr 17, 2017 10:42 am
by Mr_Noodle
You can do it with a shellscript. Off the top of my head, it would be something like:
Code: Select all
echo "$1" > big_file.txt

This assumes big_file.txt will be in the same directory. You may need to tweak the above to fit your particular circumstances but that should at least be a starting point.

Re: Check something and write to a file

PostPosted: Thu Apr 20, 2017 9:03 pm
by givens
Mr_Noodle wrote:You can do it with a shellscript. Off the top of my head, it would be something like:
Code: Select all
echo "$1" > big_file.txt

This assumes big_file.txt will be in the same directory. You may need to tweak the above to fit your particular circumstances but that should at least be a starting point.


Thank you! This worked with one small change. Is there a way to do this with Python?

Code: Select all
echo "$1" >> big_file.txt

Re: Check something and write to a file

PostPosted: Fri Apr 21, 2017 10:08 am
by Mr_Noodle
There is but it's something you'll have to look up on your own since I don't know python well plus it's outside the realm of Hazel support.

Re: Check something and write to a file

PostPosted: Fri Apr 21, 2017 8:39 pm
by givens
Mr_Noodle wrote:There is but it's something you'll have to look up on your own since I don't know python well plus it's outside the realm of Hazel support.


Sure. I would be interested if you had a link or could explain how to set up the Python input function. For instance, if I "run shell script", which is I think what I would do, I would modify the shell from bash to python. I see a statement that says use $1 to refer to file. I am wondering what to do to pass this information onto Python instead. Also mentioned in some cases are inputAttributes. What would I do to pass these along?

Re: Check something and write to a file

PostPosted: Mon Apr 24, 2017 10:49 am
by Mr_Noodle
Enter python into the shell field. It will become apparent after that.