Page 1 of 1

How to correctly use the embedded script option?

PostPosted: Fri Aug 25, 2017 7:43 pm
by phrozenpenguin
I've been using Hazel for a while but now doing some more complicated (for me) things.

I want to drop a CSV file in a folder, have it processed by an R script (which I have been using for years and is fine) which outputs an output file, and then the original input file is moved.

I have it working but I don't think it is the most efficient, as I am getting Hazel to rename the file before the script is called, and then the filename is hard coded. I can't get the filename to be passed from Hazel to R, and also can't see much info in the logs. I've read the user guide https://www.noodlesoft.com/manual/hazel/attributes-actions/using-shell-scripts/ but think I am missing something basic as I am not a terminal expert.

My shell is
Code: Select all
/usr/local/bin/Rscript

The first line of the code that works - hard coded
Code: Select all
data <- read.csv("~/Dropbox/testing\ related/input.csv", fileEncoding="latin1")

The code that doesn't work - trying to pass the path and file name
Code: Select all
data <- read.csv("$1", fileEncoding="latin1")

Any advice appreciated.

Re: How to correctly use the embedded script option?

PostPosted: Mon Aug 28, 2017 11:03 am
by Mr_Noodle
I don't know anything about Rscript but I'm guessing it has its own way of referring to arguments passed in. I'm guessing "$1" isn't it.

Re: How to correctly use the embedded script option?

PostPosted: Wed Sep 13, 2017 2:32 am
by phrozenpenguin
I have done some reading and experimenting with how Rscript expects things to be passed in, and you are right it was not how I was trying. However, I'm still having issues. Is there a way to see the actual error, or any output from the command line? The log just shows:

[Error] Shell script failed: Error processing shell script on file [path to csv].
hazelworker[33022] Shellscript exited with non-successful status code: 1

Re: How to correctly use the embedded script option?

PostPosted: Wed Sep 13, 2017 11:27 am
by Mr_Noodle
Turn on debug mode as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

That will show the output of the script in the logs.

Re: How to correctly use the embedded script option?

PostPosted: Thu Sep 14, 2017 6:47 am
by phrozenpenguin
Excellent, that was what I was looking for. Haven't had a chance to fix up yet, but hope to at some point.