osascript wait for input before starting next line

ImAMacGuy
Valued Contributor II

I have an osascript I want to wait for input before proceeding to next line, I THINK I need to do a set T in it but It keeps failing...

#!/bin/bash

loggedInUser=$(stat -f%Su /dev/console)
loggedInUID=$(id -u $loggedInUser)

if [[ "$loggedInUser" != "root" ]] && [[ "$loggedInUser" != "_mbsetup" ]]; then
    ## Create local script
    cat << EOD > /private/tmp/computerrenamescript.sh
#!/bin/bash

TT=$(/usr/bin/osascript -e 'tell application "System Events" set T to set MacTYPE to text returned of (display dialog "Please input the machine type - " default answer "" with icon 2)')

BB=$(/usr/bin/osascript -e 'tell application "System Events" to set BRAND to text returned of (display dialog "Please input the brand - "" with icon 2)')
.
.
.

Any help is appreciated!

1 REPLY 1

ehemmete
New Contributor II

Try your osascript lines like this:

TT=$(/usr/bin/osascript -e 'set MacTYPE to text returned of (display dialog "Please input the machine type - " default answer "" with icon 2)')

BB=$(/usr/bin/osascript -e 'set BRAND to text returned of (display dialog "Please input the brand - " default answer "" with icon 2)')

You shouldn't need 'tell application "System Events"' and you were missing the 'default answer ""' part of BB, but ended up with an extra '"'. I assume the '$' has something to do with this being written out to a file, so I left those.