1

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?

  • 1
    I'm _guessing_ you want something like `expect` (a scripting language built on top of TCL that's specialized to automate other programs, reading their output and writing to their input) -- although that's exactly the opposite of what your title asks for. Although maybe you want a heredoc, to be able to write text to `ask`'s stdin? It's very unclear what you _actually want_, so it's not clear how to answer. – Charles Duffy Aug 19 '20 at 18:52
  • ...when you say "pass text through bash command" -- *which* text, specifically, should be passed through *which* bash command? – Charles Duffy Aug 19 '20 at 18:53
  • @CharlesDuffy Sorry I'm very new to shell, as in I'm learning it specifically for this small project. I will look into that. As for how the question is phrased, I don't entirely understand what i'm working with or how the 'ask' command works, so its difficult to explain what I need. Thanks for the help! – prosleepingbagracer Aug 19 '20 at 18:55
  • 1
    Backing up: When you say "pass a question", do you want your question to be written _to the `ask` command_? (If so, what you want is probably a heredoc: `ask < – Charles Duffy Aug 19 '20 at 18:57
  • @CharlesDuffy After the 'ask dialog' is invoked, it brings up the 'Welcome to Ask Dialog'. I am trying to basically paste text into the command line from there. – prosleepingbagracer Aug 19 '20 at 18:58
  • 1
    Great -- sounds like a heredoc really is what you want, then; we do have several Q&A entries describing how to do that. – Charles Duffy Aug 19 '20 at 18:58
  • 1
    See f/e the answer to [How do I provide input to a C program from bash?](https://stackoverflow.com/questions/16508817/how-do-i-provide-input-to-a-c-program-from-bash) -- note that while the question goes into a lot of C-specific detail, the answer is quite generic. – Charles Duffy Aug 19 '20 at 18:59

2 Answers2

0

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

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.

Mig82
  • 4,856
  • 4
  • 40
  • 63