Skip to main content
Tweeted twitter.com/askdifferent/status/737150545056673792
Further explanation of goals
Source Link
I0_ol
  • 721
  • 2
  • 9
  • 21

I have two pieces of code. One is Applescript and the other a Bash shell script. The shell script needs to run concurrently with the applescript, return some values and then exit. The problem is the shell script's read -p prompt does not pause for user input when called from within applescript using do shell script "/path/to/script.sh".

I thought maybe

display dialog "Query?" default answer ""
set T to text returned of result

could replace the read -p prompt but I can't figure out how to make either way work. How cam use either of these methods to properly ask and wait for user entry?

I realize I could cut the applescript in two sections placing one at the beginning of the shell script and one after the last shell command.

#!/bin/bash

osascript ~/Start_Script.scpt

echo 'enter some Text'
read -p "" T

## for things in stuff do more 
## stuff while doing other things
## done 

osascript ~/End_Script.scpt

This is what I've been doing and it does work. But it requires using the terminal which is fine for me. But if I wanted to show someone like my Mom.. well she's just not going to open the Terminal app. So it would be nice to find a way to emulate the read -p command within Applescript itself and be able to pass a variable along to the embedded shell script.

I have two pieces of code. One is Applescript and the other a Bash shell script. The shell script needs to run concurrently with the applescript, return some values and then exit. The problem is the shell script's read -p prompt does not pause for user input when called from within applescript using do shell script "/path/to/script.sh".

I thought maybe

display dialog "Query?" default answer ""
set T to text returned of result

could replace the read -p prompt but I can't figure out how to make either way work. How cam use either of these methods to properly ask and wait for user entry?

I have two pieces of code. One is Applescript and the other a Bash shell script. The shell script needs to run concurrently with the applescript, return some values and then exit. The problem is the shell script's read -p prompt does not pause for user input when called from within applescript using do shell script "/path/to/script.sh".

I thought maybe

display dialog "Query?" default answer ""
set T to text returned of result

could replace the read -p prompt but I can't figure out how to make either way work. How cam use either of these methods to properly ask and wait for user entry?

I realize I could cut the applescript in two sections placing one at the beginning of the shell script and one after the last shell command.

#!/bin/bash

osascript ~/Start_Script.scpt

echo 'enter some Text'
read -p "" T

## for things in stuff do more 
## stuff while doing other things
## done 

osascript ~/End_Script.scpt

This is what I've been doing and it does work. But it requires using the terminal which is fine for me. But if I wanted to show someone like my Mom.. well she's just not going to open the Terminal app. So it would be nice to find a way to emulate the read -p command within Applescript itself and be able to pass a variable along to the embedded shell script.

Source Link
I0_ol
  • 721
  • 2
  • 9
  • 21

How can I run a shell script that prompts for user input from within Applescript

I have two pieces of code. One is Applescript and the other a Bash shell script. The shell script needs to run concurrently with the applescript, return some values and then exit. The problem is the shell script's read -p prompt does not pause for user input when called from within applescript using do shell script "/path/to/script.sh".

I thought maybe

display dialog "Query?" default answer ""
set T to text returned of result

could replace the read -p prompt but I can't figure out how to make either way work. How cam use either of these methods to properly ask and wait for user entry?