When running a script from the scripts menu, where is console output captured

command lineconsolescript

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?

Best Answer

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