Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to Use Voice to Capture a Number then assign to a variable

Hi,

I have seen many examples where you can use applescript to listen for a response and then when hearing the specific response, such as Yes or No, then you can process based on that. Is there a way to have Speech listen for any value and then assign that value to a variable that I could use later in the script?


My example is:

Ask the end user for a number between 1 and 5,000

Based on the number they pick, let's just pop up a dialog box that says, the number you said was xxx where xxx is the value of what they said.


Thanks!

Posted on Dec 12, 2017 3:30 PM

Reply
Question marked as Best reply

Posted on Dec 13, 2017 8:23 AM

And a pure AppleScript solution with try block to catch user cancel event and end processing, or loop until user actually speaks (or enters) a number, and presses return.


use scripting additions


set intvalue to ""

set status to false


repeat while status is false

try

set intvalue to text returned of (display dialog "Speak a number: " default answer "") as integer

if intvalue ≥ 1 and intvalue ≤ 5000 then set status to true

on error number -128

return -- user clicked Cancel

end try

end repeat


display dialog "Class of intvalue is :" & class of intvalue

3 replies

There are no replies.

Applescript to Use Voice to Capture a Number then assign to a variable

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.