Help with Templater error when running custom function

Hello all. I’ve tried implementing a custom function using the Templater plugin that will execute a curl command and pull some weather forecast text for inclusion. The command works perfectly in Terminal, but in Obsidian it can’t find one of the programs the command calls. Here’s the command:
curl -s,49/forecast | fx .properties.periods[0].detailedForecast

Running in Terminal gives this output…
Sunny, with a high near 107. West wind 5 to 10 mph.

But when the template runs in Obsidian, I get this error in the console:

main.ts:213 Error with User Template NWSdayforecastAZA Error: Command failed: curl -s,49/forecast | fx .properties.periods[0].detailedForecast
/bin/sh: fx: command not found
(23) Failed writing body

    at ChildProcess.exithandler (child_process.js:312)
    at ChildProcess.emit (events.js:315)
    at maybeClose (internal/child_process.js:1021)
    at Socket.<anonymous> (internal/child_process.js:443)
    at Socket.emit (events.js:315)
    at Pipe.<anonymous> (net.js:674)

Things I have tried

It seems like it’s failing to find fx, which I installed using Homebrew to parse the JSON file from the retrieved URL. Maybe Obsidian can’t just run it like Terminal for some reason? Not being an expert in such things, I can’t imagine why a command from Obsidian wouldn’t just run like a command entered straight into Terminal. Are Homebrew-installed packages treated differently somehow?

What I’m trying to do

Just trying to get that command to execute properly/without error.

I ended up finding a workaround by downloading the pre-compiled binary of fx for macOS and sticking it in my /usr/local/bin folder and including the whole path to that binary in the command. Annoying, but it did the job. The templater command now works as intended.

This problem would still happen for anyone trying to run any other commands using a brew-installed program, though, so it would be nice to know a solution to the original error.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.