Displaying an Xcode variable in a shell script in an alert fails to display the alert

81 views Asked by At

I have a shell script that I run from Xcode to open the root folder in the Terminal. It works as expected when invoked by a function key in Xcode and opens a Terminal window pointing to the value of $SRCROOT as defined in Xcode and an alert with the expected message appears before that.

#! /bin/bash
osascript -e 'display dialog "message" with title "Hi"'
open -a Terminal "$SRCROOT"

Yet when I try to replace "message" to display the contents of $SRCROOT, the dialog doesn't display at all. I've tried all of the approaches listed in the solutions here: osascript using bash variable with a space

Using any of those approaches results in the alert not displaying at all.

I even tried to display the contents of $SRCROOT in a notification with various methods of escaping it but that just displays an empty notification.

Any ideas? TIA.

1

There are 1 answers

1
Philippe On

Save following in test.sh :

#!/usr/bin/env bash
SRCROOT=~/Developer/SwiftVC
osascript \
  -e "on run(argv)" \
  -e 'display dialog item 1 of argv with title "Hi"' \
  -e "end" \
  -- "$SRCROOT"
open -a Terminal "$SRCROOT"

and run it with :

chmod +x test.sh
./test.sh