I/O for external scripts

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

Moderator: Mr_Noodle

I/O for external scripts Fri Aug 12, 2022 12:46 pm • by zabouti
I have a directory named /Users/ge/Dropbox/obsidian/home/books/marcel-proust/proust--a-la-recherche-du-temps-perdu/02--Du-côté-de-chez-Swann--Deuxième-partie.

I've pointed Hazel at this directory

The first file of interest is 02-Un-amour-de-Swann.pdf. I use the Highlights PDF app to write notes in this PDF file.

Highlights creates a markdown sidecar file named 02-Un-amour-de-Swann.md each time that I save the PDF file.


I've written a Ruby script that modifies the markdown sidecar file. Each time that the sidecar file changes, I want Hazel to run that script and save the output in another file.

Here is the exact shell command. It works when executed by hand in this directory:

Code: Select all
$ cat 02-Un-amour-de-Swann.md | /Users/ge/Dropbox/obsidian/home/books/marcel-proust/chronologie/matthews/mk-chronologie-highlights-md-md.rb > 02-Un-amour-de-Swann-2022-08-11.md


Note that I'm sending the sidecar file to the script's STDIN file handle.

I want Hazel to do this each time the sidecar is recreated. But as far as I can tell, the only way Hazel can tell an external script where a file is is to pass it as a command-line argument, visible to a shell script as $1 or to a Ruby script as ARGV[0]. In other words, Hazel doesn't seem able to supply a file to the script's STDIN file handle.

I think I can work around this limitation, but I'd like to know if my understanding of Hazel external scripting is correct.

1. Can Hazel provide a file to a script's STDIN?
2. Can Hazel save STDOUT from an external (or internal) script to a specific file, say with the "Sort into subfolder" command?
3. Can someone suggest a workaround?
zabouti
 
Posts: 5
Joined: Sun Dec 09, 2007 1:32 am

Re: I/O for external scripts Mon Aug 15, 2022 9:27 am • by Mr_Noodle
Hazel does not send anything via stdin. Is there a reason why you can't have your script "cat" the file as well?

Hazel will store stdout as possible output to the log. Hazel will not interpret anything on stdout. You will need to write it out to a file.
Mr_Noodle
Site Admin
 
Posts: 11551
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: I/O for external scripts Mon Aug 15, 2022 3:59 pm • by zabouti
Mr_Noodle wrote:Hazel does not send anything via stdin. Is there a reason why you can't have your script "cat" the file as well?

Hazel will store stdout as possible output to the log. Hazel will not interpret anything on stdout. You will need to write it out to a file.


Okay, I give up. A good old-fashioned Makefile will do the trick:

Code: Select all
02-Un-amour-de-Swann-annotated.md: 02-Un-amour-de-Swann.md
        cat 02-Un-amour-de-Swann.md | /Users/ge/Dropbox/obsidian/home/books/marcel-proust/chronologie/matthews/mk-chronologie-highlights-md-md.rb > 02-Un-amour-de-Swann-annotated.md



Can Hazel at least execute a make command? I tried, but it did nothing.

I think Hazel need a lot more documentation for this area, perhaps with one or two examples?
zabouti
 
Posts: 5
Joined: Sun Dec 09, 2007 1:32 am

Re: I/O for external scripts Tue Aug 16, 2022 9:17 am • by Mr_Noodle
I'm not sure what issue you are having here. Hazel can run scripts and you can put whatever you want in the scripts. Not sure why a makefile is necessary here.
Mr_Noodle
Site Admin
 
Posts: 11551
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: I/O for external scripts Wed Aug 17, 2022 12:03 pm • by zabouti
Mr_Noodle wrote:I'm not sure what issue you are having here. Hazel can run scripts and you can put whatever you want in the scripts. Not sure why a makefile is necessary here.


The reason is that that Hazel won't let me redirect STDOUT, or if it can, you haven't told me how to do it.

The Makefile does it very simply.

Can Hazel execute this makefile?
zabouti
 
Posts: 5
Joined: Sun Dec 09, 2007 1:32 am

Re: I/O for external scripts Wed Aug 17, 2022 12:20 pm • by zabouti
Mr_Noodle wrote:I'm not sure what issue you are having here. Hazel can run scripts and you can put whatever you want in the scripts.


That's great news!

So when I change 02-Un-amour-de-Swann.md Hazel runs the script with no error messages:

Code: Select all
cat $1 | /Users/ge/Dropbox/obsidian/home/books/marcel-proust/chronologie/matthews/mk-chronologie-highlights-md-md.rb > 02-Un-amour-de-Swann-annotated.md


This makes me very happy except for the fact that the file 02-Un-amour-de-Swann-annotated.md is nowhere to be found.

I have an idea. Instead of trying to make me feel stupid by telling me that Hazel can do this and do that, why not show me how to do it?
zabouti
 
Posts: 5
Joined: Sun Dec 09, 2007 1:32 am

Re: I/O for external scripts Wed Aug 17, 2022 4:56 pm • by zabouti
Image

Here's what I'm trying to do. Can you tell me how to do it?
zabouti
 
Posts: 5
Joined: Sun Dec 09, 2007 1:32 am

Re: I/O for external scripts Thu Aug 18, 2022 8:55 am • by Mr_Noodle
You should print out the current directory as it may not be what you expect. In general, it's a good idea to use full paths where possible.
Mr_Noodle
Site Admin
 
Posts: 11551
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support

cron