using "ask dialog" command to immediately pass text through Bash command

147 Views Asked by At

I want to use the "ask dialog" command to immediately pass a question. I am trying to automate the process of launching terminal and running "ask dialog". Whenever my bash script runs, it pauses once the Alexa instance opens.

#!/bin/bash/
cd /Users/AlexaDirectory/
ask dialog 
#this is where I need to ask Alexa a question automatically. 
#I have tried running "ask dialog && (insert question)", but the script pauses once it reaches "ask dialog"
echo "end"

Here's what i usually see when running the .sh

MacBook-Pro Desktop % bash Test.command
Defaulting locale to the first value from the skill manifest: en-US

======================================= Welcome to ASK Dialog =======================================
=========== In interactive mode, type your utterance text onto the console and hit enter ============
===================== Alexa will then evaluate your input and give a response! ======================
=== Use ".record <fileName>" or ".record <fileName> --append-quit" to save list of utterances to a file. ===
=============== You can exit the interactive mode by entering ".quit" or "ctrl + c". ================

User  > 

If it is not possible to pass a question immediately, would it be possible to send keystrokes to the terminal?

2

There are 2 best solutions below

0
prosleepingbagracer On BEST ANSWER

With help from Charles Duffy, using a herestring is the answer.

The process freezes when the ask dialog is invoked, and the fix is sending ask dialog <<< "question for alexa placed here". This immediately ends the Alexa instance too.

0
Mig82 On

You can try using the expect command. I've been struggling with a similar problem. Running ask init in non-interactive mode. In the end I solved it like this.

echo '#!/usr/bin/expect 
spawn ask init 
expect "? Skill Id (leave empty to create one):" 
send "my-skill\r" 
expect "? Skill package path:" 
send "./path/to/skill-package\r" 
expect "? Lambda code path for default region (leave empty to not deploy Lambda):" 
send "./path/to/lampda-package\r"
' > ask_init.sh
chmod u+x ask_init.sh 
./ask_init.sh

FYI, I had also tried piping answers to it using a combination of | and echo, like this:

echo 'quantum-skill
./path/to/skill-package
./path/to/lampda-package
' | ask init

and with printf, like this:

printf 'quantum-skill\n./path/to/skill-package\n./path/to/lambda-package\n' | ask init

Neither one of the latter worked. So I recommend using expect instead.