Re: osascript and dialogs
Re: osascript and dialogs
- Subject: Re: osascript and dialogs
- From: Joshua See <email@hidden>
- Date: Tue, 10 Jun 2003 18:02:54 -0500
On Tuesday, June 10, 2003, at 11:27 AM, Christopher Nebel wrote:
On Tuesday, June 10, 2003, at 08:01 AM, matt neuburg wrote:
The following puts the computer into a bizarre state:
Yes, Matt? cat > textfile
display dialog "Hello, world!"
[^D]
Yes, Matt? osacompile -o compiledfile textfile
Yes, Matt? osascript compiledfile
The dialog appears, but refuses to let me click on it. Appending "&"
doesn't help - in fact, it makes it worse, since there's now
absolutely no
way to get rid of the dialog short of killing osascript. What's the
problem here? Thx - m.
It's a bug. In fact, it's not supposed to work at all -- osascript
should fail with a "no interaction allowed" error. (It's got no UI.)
Tell some other application (e.g., Finder) to display the dialog.
There is a workaround, which hopefully won't get "fixed" anytime soon.
Since osascript doesn't have a GUI, hand the display dialog command off
to something that does. Please forgive the (ab)use of cat.
% cat > ~/Documents/dogcow.txt
tell application "Finder"
activate
-- no line breaks till the next comment
display dialog "Welcome to Macintosh, Clarus." with icon 1 default
answer "Mooooof!" buttons {"Cancel", "OK"} default button 2 giving up
after 30
-- resume normal line breaks
return text returned of the result
end tell
[^D]
% osascript ~/Documents/dogcow.txt
That should cover most dialog features that you'd want to use. The
command will exit status 0 when the user clicks "OK" or when it times
out. Clicking "Cancel" will exit status 1. Any answer from the user is
returned naked to the stdout, which is handy for shell redirects.
The reasoning behind osascript is a bit of mystery to me. It has the
interactivity prevention, which means it isn't intended for
user-centric scripts or as a substitute for GUI script editors.
However, it won't take arguments even though the syntax "on run
({arglist})" in AS offers an obvious means of supporting them, and it
chokes on shebangs, which means it isn't meant for Mac-friendly shell
scripting or automation, either. Why does this program exist?
--
Sincerely,
Joshua See
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.