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.

2
  • Any error messages, or an example of how you attempted to add $SRCROOT to the message? Commented Jan 30, 2023 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. Commented Jan 30, 2023 at 21:13

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.