Jump to content

Terminal Command: How to prevent automatic `read` statement input/submission


Recommended Posts

I would like to open a new terminal window with Alfred to run a preset bash script (e.g. `my_script`).

 

The script has a confirmation prompt that affects the behavior depending on the value provided.

 

read -p "Start processing? (y/n): " conf_process

 

The script stops at this prompt when run directly from a terminal window.

However, when a script is run Alfred's Terminal Command action, it appears that the first `read` statement in the script is automatically executed without any input.

 

How can I run scripts via Alfred's Terminal Command without the first `read` statement being bypassed?

Edited by Archetyped
Link to comment
  • Archetyped changed the title to Terminal Command: How to prevent automatic `read` statement input/submission

Thanks.  There was no explicit newline in the Terminal Command itself, but thanks to your comment, I started looking at the other actions that process the values sent to the Terminal Command action.

 

I learned that output from the Run Script action can add a newline unless it is explicitly suppressed.  Changing the final echo statement in that action to do just that resolved the issue:

 

echo -n "${output[@]}"

 

Thanks!

Link to comment
47 minutes ago, Archetyped said:

I learned that output from the Run Script action can add a newline unless it is explicitly suppressed.

 

Run Script sends the script’s output without modifying it. echo does indeed send a newline without -n; printf sends without a newline unless you add one (\n) AppleScript and JXA always send a newline, except if you bend over backwards to avoid it. There’s a Transform Utility which can trim surrounding whitespace that will guarantee the newline isn’t passed to the next action.

Link to comment
56 minutes ago, vitor said:

Run Script sends the script’s output without modifying it. echo does indeed send a newline without -n; printf sends without a newline unless you add one (\n) AppleScript and JXA always send a newline, except if you bend over backwards to avoid it. There’s a Transform Utility which can trim surrounding whitespace that will guarantee the newline isn’t passed to the next action.

 

Thanks for the tips 👍

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...