My_Play_Lists ~BlackCatWhiteTail’s blog~

Talk About My Favorite Songs

applescript + numbers > display dialogを利用する。

 VBAはメッセージボックス、インプットボックスで対話的に入力できる。これらの機能はかなり強力で、ユーザーフォームを作ったりできる(ユーザーフォームの利用 | エクセル職人, https://excel-pro.info/06_excel-VBA_21.html)。

 applescriptの似た機能にdisplay dialogがあるが、VBAのメッセージボックスほど色々できるわけではない。しかし、applescriptの対話的に入力する機能はこれしかない(多分)ので、このdisplay dialogを利用して対話的に入力してみる。(鳶嶋工房 / AppleScript / 入門 / インテリジェントでいこう, http://tonbi.jp/AppleScript/Introduction/07/

基本的な使い方

resultで直前の結果を取り出す。 ・resultにはrecord型で結果が収まる。 ・文字列を取り出すときは、text returnedを用いる。 ・選択したボタンを取り出すときは、button returnedを用いる。

'OK'ボタンを押した結果を取り出す。

・'キャンセル'を押すとプログラム実行がその時点で中断される。

display dialog "test" -- select 'OK' button
button returned of result -- 文字列'OK'を取り出せる。

'テキストボックス'に入力した文字列を取り出す。

display dialog "test" default answer "AAAAA"
text returned of result -- 文字列'AAAA'を取り出せる。

(こんな事が出来るとは知りませんでした。[AppleScript]:Macはからだの一部です。:SSブログ, https://start-mac.blog.ss-blog.jp/2008-01-25)。

・テキストボックスは改行文字をいれれば、複数行にもできる。

display dialog "test" default answer "AAAAA\nBBBB"
text returned of result

OKボタンを押した結果とテキストボックスに入力した文字列をそれぜれNumbersのセルに入力してみる。

set LF to "\n"

tell application "Numbers"
    activate
    set tgtDoc to make new document
    tell tgtDoc
        tell sheet 1
            delete every table
            set tgtTable to make new table with properties {row count:10, column count:10, header row count:0, header column count:0}
            tell tgtTable
                set height of every row to 36
                set width of every column to 36
                
                display dialog "test"
                set theButton to button returned of result
                set value of cell "A1" to theButton -- The string 'OK' will be entered in cell 'a1'.
                
                display dialog "テキストを入力:" default answer "Line1" & LF & "Line2" & LF
                set theText to text returned of result
                set value of cell "B1" to theText -- The string inputted in textbox will be entered in cell 'b2'.
                
                
            end tell
            
        end tell
    end tell
    
end tell
Translated with DeepL

 VBA allows you to type interactively in 'message boxes' and 'input boxes'. These features are quite powerful and can be used to create user forms (Using User Forms | Excel Craftsman, https://excel-pro.info/06_excel-VBA_21.html).

 A similar feature in applescript is the 'display dialog', but it does not do as much as the message box in VBA. However, since this is the only way to input data interactively in applescript (probably), I will try to use this 'display dialog' to input data interactively. (Tobishima Kobo / AppleScript / Introductory / Intelligent, http://tonbi.jp/AppleScript/Introduction/07/)

Basic usage

Extract the previous result with result. The result is stored in the record type. If you want to retrieve a string, use text returned. Use button returned to retrieve the selected button.

The result of pressing the 'OK' button is retrieved.

If you press `cancel', the program execution will be aborted at that point.

Retrieves the string entered in the 'text box'.

(I didn't know this was possible.(I didn't know you could do this. (I didn't know this was possible.) [AppleScript]: Mac is a part of your body. (AppleScript]: Mac is part of your body, SS Blog, https://start-mac.blog.ss-blog.jp/2008-01-25).

Try to enter the result of the OK button and the text in the text box into the respective Numbers cells.

 このウェブサイトについて

 練習用のサイトです.

 自分の好きな曲について感想を述べます.

 また,世に役に立つかもと考えたことも書きます.

 

TOP 1 To 5

Title Artist Album
ロックバンド 中村中 私を抱いて下さい
犬の生活 SEX MACHINEGUNS SEX MACHINEGUNS
Megalovania Toby Fox UNDERTALE Soundtrack
Bokura No Fly Away Base Ball Bear Bokura No Fly Away - single
人魚の檻 陰陽座 迦陵頻伽(Ka Ryo Bin Ga