Hello, I'm getting the "Macro Cancelled" popup, indicating that Task Failed with status 1. See the macro setup:
Any help is appreciated. Thank you!
Hello, I'm getting the "Macro Cancelled" popup, indicating that Task Failed with status 1. See the macro setup:
Any help is appreciated. Thank you!
That error probably means there was an error in your script.
If you show your script, it's possible someone might be able to spot your error.
Of course, we don't want to see personal details in your script.
Did you try to run the script manually from a terminal window? You might get a more informative error message.
At this point my best guess is that the first line of your script didn't contain the name of the shell that you need. That's a common problem. Do you know which shell your script requires?
Airy, Thank you for your reply.
Yes, the script works when run manually from a terminal window.
Here's the script:
#!/bin/sh
if test $# -lt 1
then
echo "Usage: $0 needs one parameter,"
echo "the backup mode, i.e. daily, weekly or monthly."
exit 1
fi
mode="$1"
report="/Users/xxx/Downloads/htmlval/report"
url="https://example.com/${mode}"
json_file=$(echo "${mode}" | sed "s#\/#\-#g")".json"
curl ${url} | htmlval -j >${report}/${json_file}
bbedit ${report}/${json_file}
Hmm. In that case, since it works, did you check the permissions on your ".sh" file?
That may also be a dead end. The problem may be that when you are using a Terminal window, you are using the correct environment variables, which includes a PATH, but when you execute the program in a shell, it's not setting the PATH correctly (or other environment variables that your script depends on, including the default path.) This may be the cause of the problem, but I'm not sure what the simplest solution is. It's up to you to make sure that your path and environment are correct.
The .sh file permissions: -rwxr-xr-x@
Is there a way to get additional diagnostic information?
Perhaps. To prove or disprove my theory, you can try to run your script in the Terminal window, but before running it, change your current directory and delete your PATH variable. This way, when it fails, it will probably give you more information.
But even without that information you can probably fix it by setting the correct PATH inside your script, so that when KM runs it, it is correct. You may also need to set your current folder inside your script.
There are people on this site who can solve this much quicker than me, but I'm on my way out to an appointment, so you may have to rely on them, or try my suggestions.
Are you sure the system clipboard has valid data? Try setting a variable (local_myVar
) to some valid text, then change the script to use the passed-in variable, i.e. /Users/xxx/sh/htmlval.sh %Variable%local_myVar%
. (I think that's the proper structure, but I don't normally call shell script files.)
If it works that way, then it's bad clipboard data that's causing the failure.
Also look at the log file to see if it has any additional information about the failure.
-rob.
Thank you, griffman.
Yes, you're right the script set the exit code to 1 because the expected parameter wasn't passed. I'm still having problem setting a variable and passing its value to the script, or referencing the variable within the script.
I'm glad you identified the problem. I was just assuming that one of your programs read data from the input stream, but it seems that you were trying to use the input stream to pass parameters to the shell script.
Here's a simple example of how you would pass a KM variable to a shell script as a parameter to the script:
The shell file contains this:
When you run those KM actions, you will get the word "Hello," displayed, as that corresponds to $1.
It worked.
Thank you so much!
You are welcome. I'm sorry I didn't realize the issue earlier.
If you check the gear menu, and ensure you turn off Failure Aborts Macro, and turn on Include Errors, then the window would show the errors in the script, which would aid in debugging the problem.
Very good to know. Thank you!