Archetyped Posted November 16 Share Posted November 16 (edited) 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 November 16 by Archetyped Link to comment
vitor Posted November 17 Share Posted November 17 What is likely happening is that in your Terminal Command you added a newline, i.e. pressed ↩ at the end of the command. Thus that is being sent as well, and pressing a ↩ which is interpreted by read. Archetyped 1 Link to comment
Archetyped Posted November 17 Author Share Posted November 17 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
vitor Posted November 17 Share Posted November 17 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. Archetyped 1 Link to comment
Archetyped Posted November 17 Author Share Posted November 17 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now