Problem returning text from a shell script to a dialog box

I’m working on a script which needs to provide the user some feedback from the CLI. I would like to use “do shell script” and have the feedback displayed in a dialog box similar to the example below but I’m having a problem actually getting the text I want returned.

This example works:

set dialog_text to do shell script "date"
display dialog dialog_text

My script is for working with GPG signed archives. I would just use GPGFile Tool but it doesn’t do exactly what I want (verify the archive and extract a copy of the enclosed document in one step.) Here’s the command which does what I want entered straght into the CLI (text is edited for anonymity):

fingal$ gpg “/Users/fingal/Desktop/AppleScripts for GPG - open/transcription copy 5.doc.gpg”
gpg: Signature made Mon Jul 11 15:18:51 2005 EDT using DSA key ID 3E5F3C58
gpg: Good signature from “Aram Fingal

I want to have the two lines (beginning with “gpg:”) which are returned from GPG displayed in a dialog box when this command is run using “do shell script” as in the AppleScript below (you will, of course, have to have GPG installed in order to run this). What happens is that the document is properly extracted but I get a blank dialog box. How can I get the dialog box part to work?

display dialog "To use this script, drag one or more signature files or a signed archives to it."

on open files_dragged_to_this_script
	repeat with each_file in files_dragged_to_this_script
		set shell_script to "/usr/local/bin/gpg " & "\"" & POSIX path of each_file & "\""
		set dialog_text to (do shell script shell_script)
		display dialog dialog_text
	end repeat
end open

You may try pipe(ing) the results to a tmp text file. Eg:

do shell script "blah > /tmp/log.txt"
display dialog (read ("/tmp/log.txt" as posix file))

If I put the command I’m using in your suggested script, the dialog box returns “End of file error.” I checked out /tmp and, the file is there but it’s empty. I think the problem has something to do with how UNIX does output. I’m a little vague on these UNIX concepts but I think the issue might have to do with whether the message is “standard output” or not. If it’s not “standard output,” then what do I do to capture the text?

Your script does work for me if I use another command besides the one I’m working on.


Hmmm… I’ve just installed gpg to test it, and this works fine here:

do shell script "/usr/local/bin/gpg /Volumes/dir/sig.sig > /tmp/sig.txt"

display dialog (read ("/tmp/sig.txt" as POSIX file))

I just tried it again with two other machines and it worked on one and not the other. I wonder if it could be an issue of the default shell. If I remember right, “do shell script” will use sh by default regardless of what you have set as your login default (in Netinfo Manager) but could it be different on different machines?

Update: It works in a different user account, with the same default shell as mine, on my main machine, where it still doesn’t work in my own user account.