Wget not working

Hey everyone,

I'm trying to have KM run a .sh script when a program is activated. It run's everyone fine, except it doesn't seem to download the file I pointed it to with wget.

When I run the .sh file via terminal it works fine. any ideas?

Here is the code

curl -X POST http://MYDOMAIN.com/csv/csv.php
sleep 5
cd /Users/USERDIR/Documents/FILEPATH/
wget  http://MYDOMAIN.com/csv/labelValues.csv

I also attached a screenshot of the KM settings

Short answer: In your script, use the full path to wget. Keyboard Maestro macros don't run in the same environment as scripts run from the Terminal, and the PATH environment variable doesn't include the directory where wget is. Using the full path will get around that problem.

Long answer: Set the Keyboard Maestro variable ENV_PATH to match the PATH you use in Terminal, and you'll never have to worry about this again. See this post for ideas on how to do that.

I considered that, but I used absolute paths and used PWD to make sure the app was in the right spot.

Anything I might be overlooking?

No idea why wget doesn't work, but curl seems to do the trick

#!/bin/sh
curl -X POST http://MYDOMAIN.com/csv/csv.php
sleep 2
cd /Users/USERDIR/Documents/FILEPATHDestination/
curl -O http://MYDOMAIN.com/csv/labelValues.csv

FYI for anyone using my code as a template for their needs. I need to do a curl post call in order to update the file. If you don't need to do that, only the last two lines are needed.

#!/bin/sh
cd /Users/USERDIR/Documents/FILEPATHdestination/
curl -O http://MYDOMAIN.com/csv/labelValues.csv

I don't understand how pwd can get you the absolute path to wget, but I'm glad you got things working.

I used absolute paths to describe where to put files. I had the script show the Pwd so I can confirm it’s in the correct place

I am sure the great @drdrang means you should use a full path to the command.
Like this:

/usr/local/bin/curl -X POST http://MYDOMAIN.com/csv/csv.php
sleep 5
cd /Users/USERDIR/Documents/FILEPATH/
/usr/local/bin/wget  http://MYDOMAIN.com/csv/labelValues.csv

Of course with other path than '/usr/local/bin/' if it is located other places on your system.

Another way is to create a variable named ENV_PATH. And the contents of this variable should be the paths where Keyboard Maestro should look for commands when running shell scripts.

Here is mine from the preferences:

1 Like