Thursday 26 July 2018

macos - Dialog display with blank field assigned to variable in Mac Terminal?


I want to make a display box that has a text box that the user can enter a number into that will later be assigned to a variable. How would I do this?



Answer



Open AppleScript Editor, enter the following and save as script:


tell application "Terminal"
repeat while true
set input to display dialog "Enter a number:" default answer ""
if button returned of input is equal to "OK" then
try
return (text returned of input) as number
end try
end if
end repeat
end tell

(we need to tell application, because otherwise osascript doesn't allow user interaction)


Then run like this:


$ osascript path/to/script.scpt

Output of the program is the number the user entered.


Store in bash variable like this:


$ foo=$( osascript path/to/script.scpt )
$ echo $foo
42

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...