0

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.

Alex Zavatone
  • 4,106
  • 36
  • 54
  • Any error messages, or an example of how you attempted to add `$SRCROOT` to the message? – tjm3772 Jan 30 '23 at 17:45
  • No error messages at all. I've used so many ways, I can't list them all. That's why I provided the link which lists many solutions. Here's a sample that just failed. `osascript -e 'display dialog "'"$SRCROOT"'" with title "Hi"'`. In this, the dialog message is empty, just like in every one of the other attempts. The correct path is opened in the Terminal window though. It's getting it to display in the AppleScript. In this case, it's just `~/Developer/SwiftVC`. – Alex Zavatone Jan 30 '23 at 21:13

1 Answers1

0

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
Philippe
  • 20,025
  • 2
  • 23
  • 32
  • Thanks Philippe. I just tried that and all I get is an empty string. FYI, the value of `$SRCROOT` in this case is `~/Developer/SwiftVC`. – Alex Zavatone Jan 30 '23 at 21:08