Dialogs

alert

alert

alert is very similar to a javascript alert dialog. It simply displays a dialog with the provided message.

    map "<Cmd-p>" do
      alert("Hello, world.")
    end

confirm

confirm

confirm displays a dialog message with “Yes” and “No” buttons that return true or false, respectively.

    map "<Cmd-L>" do
      lock_screen if confirm("Lock Screen?")
    end

input

input

input displays a dialog with a input text box. The input text is then returned.

    map "<Cmd-n>" do
      my_text = input()
    end

input can also take a block, passing in the input text.

    map "<Cmd-n>" do
      input do |answer|
        send("<Cmd-Shift-3>") if answer == "screenshot"
      end
    end

input can even take a hash that when a key matches the input text, the corresponding value code is ran.

    map "<Cmd-n>" do
      input(
        "rel" => lambda{reload}
        "ls" => lambda{lock_screen}
        "x" => lambda{send("<Cmd-q>")
        "screenshot" => lambda{send("Cmd-Shift-3")}
      )
    end

See Mnemonics for advanced usage of input dialog.

prompt

prompt

prompt is the same as input but you can provide a message to display.

    map "<Cmd-n>" do
      prompt("Please enter command") do |answer|
        send("<Cmd-Shift-3>") if answer == "screenshot"
      end
    end