Skip to content

[AppleScript] How To Make A Pop-up Dialog Component

Last Updated on 2022-06-22 by Clay

If we want to make a pop-up dialog component when we writing a script on Mac OS, we can use dialog to show a simple window. In additional to this, dialog allow us to set different button to interact with users.


How to use Dialog

Display Message

The simplest method is use message and dialog (default have two buttons).

set Message to "You have a new message!"
display dialog Message

Output:

 

Add a icon before message

If you feel it's too monotonous, you can insert some icons to let the window looks richer. There are three default icons you can select: note, stop and caution.

note icon

set Message to "You have a new message!"
display dialog Message with icon note

Output:

 

stop 圖示

set Message to "You have a new message!"
display dialog Message with icon stop

Output:

 

caution 圖示

set Message to "You have a new message!"
display dialog Message with icon caution

Output:

 

Customize button, and get the button return information

Sometimes maybe we need to make different script function according user select different button. In this way, we can use the following code to get the information of button that user pressed.

C而有時候我們會需要依照使用者選擇了不同的按鈕而做出不同的腳本功能。這時候我們可以使用以下程式碼取得使用者按下的按鈕資訊。

set Message to "You have a new message!"
set ButtonResult to the button returned of (display dialog Message buttons {"Cancel", "OK"} default button "OK" cancel button "Cancel")

# Button Result
display dialog ButtonResult

Output:


References


Read More

Leave a Reply