Running an executable with JSON output

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

Moderator: Mr_Noodle

Running an executable with JSON output Sun Nov 22, 2020 5:24 pm • by jandamm
Hi,

I want to run a executable which returns JSON and use this JSON data in Hazel (5).
It's easy to run the executable in the "Passes shell script" part but I cannot use the returned data since Hazel just uses the exit code.
I tried running an executable in JS but every snippet I found on the internet didn't work.

Has someone achieved something comparable and could give me a hint?

Cheers
Jan
jandamm
 
Posts: 8
Joined: Sun Feb 18, 2018 10:46 am

Re: Running an executable with JSON output Mon Nov 23, 2020 1:12 pm • by Mr_Noodle
What do you want Hazel to do with the JSON?
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Running an executable with JSON output Mon Nov 23, 2020 2:45 pm • by jandamm
I would want to use the values in the JSON as variables in Hazel.

I got it somewhat working with this snippet for AppleScript but it would be easier to handle JSON:
Code: Select all
set filesLists to do shell script "ls"
set AppleScript's text item delimiters to return
set theArray to every text item of filesLists
return {hazelPassesScript:true, hazelOutputAttributes:theArray}

In the settings for this step I then set output variables to grab the values.

("ls" is just for testing)


My main issue is that I've currently using many rules to sort my pdfs into DEVONthink.
The rules are written in JS and are very duplicated since they basically do a regex and return a new filename if matched.
I've started to write a kind of matcher in Swift which I know much better than JS and wanted to return a JSON which can be interpreted by Hazel and then use Hazel to rename/move etc based on the returned values.
I've thought about using just the Swift matcher but I'd prefer using Hazel for filesystem mutations since it is better tested and has error messages when something failed.
jandamm
 
Posts: 8
Joined: Sun Feb 18, 2018 10:46 am


Return to Support