$PATH in Hazel scripts

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

$PATH in Hazel scripts Thu Feb 06, 2025 2:29 am • by halloleo
Hey Mr Noodle

I have quite a few rules with embedded scripts which read a file and pass back a new file name based on content analysis. I do this analysis with a xonsh (https://xon.sh/) script.

The embedded Applescript looks like this:

Code: Select all
set filePath to POSIX path of theFile
set shellCmd to "/opt/homebrew/bin/xonsh --no-rc $HOME/opt/link/bin/name-for-CSC-statement.xsh" & " " & quoted form of filePath

set shellOut to do shell script shellCmd if shellOut is not equal to "" then
   set theRes to {hazelPassesScript:true, hazelOutputAttributes:{shellOut}} else
   set theRes to {hazelPassesScript:false} end if


This feels to me pretty convoluted and error prone because Hazel does not use my $PATH variable. (Both /opt/homebrew/bin/ and $HOME/opt/link/bin are in my $PATH.)

Is there a way to let Hazel search for executables in my $PATH variable?

Many thanks,
Leo
halloleo
 
Posts: 59
Joined: Thu Apr 27, 2017 10:10 pm

Re: $PATH in Hazel scripts Thu Feb 06, 2025 10:02 am • by Mr_Noodle
You will need to set it yourself. If it is set in one of your shells startup files, you can try sourcing/executing that though you have to be careful as some of those files may contain things only meant for interactive shells.
Mr_Noodle
Site Admin
 
Posts: 11803
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: $PATH in Hazel scripts Mon Feb 10, 2025 11:48 pm • by halloleo
Thanks for your reply.

Mr_Noodle wrote:You will need to set it yourself. If it is set in one of your shells startup files, you can try sourcing/executing that though you have to be careful as some of those files may contain things only meant for interactive shells.


With a shell startup file I could share the directory of the script ($HOME/opt/link/bin/), right? But how can I share the directory the shell it self is in (/opt/homebrew/bin/)?
halloleo
 
Posts: 59
Joined: Thu Apr 27, 2017 10:10 pm

Re: $PATH in Hazel scripts Tue Feb 11, 2025 9:28 am • by Mr_Noodle
Not sure if I follow. If you export your PATH var, you can stick whatever you want in it.
Mr_Noodle
Site Admin
 
Posts: 11803
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: $PATH in Hazel scripts Tue Feb 11, 2025 9:34 pm • by halloleo
Mr_Noodle wrote:Not sure if I follow. If you export your PATH var, you can stick whatever you want in it.


Sorry, Mr Noodle. I rephrase it. I also understand the situation better now:

The problem is that in the Hazel action Run applescript the command
Code: Select all
do shell script shellCmd
doesn't use the $PATH I have set for the shell. That's why in the action xonsh without a path is not found and I have to write /opt/homebrew/bin/xonsh.

Howver a shell command run through the Hazel action Run shell script does use my $PATH, so in this action writing plainly "xonsh" works.

Therefore, my ultimate question is: Can I do all the HazelOutputAttribute magic I have done in the Applescript from a shell script instead?

I hope this is clearer now.
halloleo
 
Posts: 59
Joined: Thu Apr 27, 2017 10:10 pm

Re: $PATH in Hazel scripts Wed Feb 12, 2025 9:37 am • by Mr_Noodle
There is no way currently to export attributes using a shell script. You will need to use Apple/JavaScript for that. Note when using a shell script, you are specifying the path somewhere. If not in the script, then in the shell field itself.
Mr_Noodle
Site Admin
 
Posts: 11803
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: $PATH in Hazel scripts Wed Feb 12, 2025 11:26 pm • by halloleo
Thanks, Mr. Noodle. Good to know.
halloleo
 
Posts: 59
Joined: Thu Apr 27, 2017 10:10 pm


Return to Support