开发者

Bash Script on a Mac creates a info popup

Is there a wa开发者_如何学Pythony in bash on a mac to draw a pretty info box that displays a simple message like "please save all files to /Users/......"


You can run fragments of applescript from you bash scripts. A simple popup would look like this:

#!/bin/bash
/usr/bin/osascript <<-EOF

    tell application "System Events"
        activate
        display dialog "Hello world"
    end tell

EOF

This will feed the applescript between the EOF tags to osascript and execute it
(resulting in a Hello World popup).


An alternative to osascript "System Events" would be to install cocoaDialog.

cocoaDialog has the disadvantage that it must be installed, but it seems to be much more flexible than the "System Events".

The license is GPL, so you can freely redistribute it, since it is a separate application.

(osascript was littering my terminal with error messages (at least under Lion) and with return values, it didn't let me do popups with timeouts, and seemed to require specific quoting which made it hard to use variables in the texts.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜