1

I have a shell script that I want to run from the scripts menu in the menu bar. (This is the menu that you can activate in the Script Editor preferences.) The script works when I run it from Terminal, but doesn't work when I run it from the scripts menu. To debug the problem, I'd like to see what error messages it's printing to the console — but I can't find the console output.

I haven't been able to find any output from my script anywhere in the Console app. Is there somewhere else I should be looking?

1

Here is an example.

Below is the text for my shell script named hither.sh. As you might guess, file nonexistant_file does not exist.

echo hi there
ls nonexistant_file

The hither.sh file is stored in my Documents folder. This is ~/Documents. The AppleScript I created is shown below.

set scriptName to "~/Documents/hithere"
set errorNumber to 0
try
    do shell script "source " & scriptName & ".sh &>" & scriptName & ".txt"
on error number errorNumber
end try
try
    do shell script "echo exit status = " & errorNumber & " >>" & scriptName & ".txt 2>&1"
end try

I saved this AppleScript to the file ~/Library/Scripts/hithere.scpt. When I run this AppleScript from the menu bar, the shell script console output and error text is redirected to the ~/Documents/hithere.txt file. Below is the resulting output.

hi there
ls: nonexistant_file: No such file or directory
exit status = 1
  • That worked, thanks. But, FYI, the scripts folder can run any kind of shell script, not just Applescript, so it's possible to simplify the wrapper script by writing it in standard bash. – Evan Feb 13 '18 at 18:37
1

You can try typing your command and following it with 2> filename.txt. This will pipe the standard error (stderr) to the specified file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .