1
defaults write '$1/Contents/info.plist' MyVariable false

For some reason, I cannot get this to work, and I've tried everything I can think of. Even through an AppleScript, instead of a shell script, with the same results.

I can have it output the command first, then copy that output, and paste it in Terminal, and it works fine. The syntax is 100% what I want. It just will NOT work in Automator. I even tried using sudo, and admin withe the AppleScript attempts, but that's not the problem.

I can output to a text file, and just like using the clipboard to paste, the syntax is correct, and functions as expected.

My goal is to be able to drag and drop an application on an Automator app, and have it add my variable to the info.plist in the application bundle.

Why would it work in Terminal, but not in Automator?

output:
defaults write '~/Desktop/MyApp.app/Contents/info.plist' MyVar false

Screenshot of Automator

1 Answer 1

0

Quoting in shells has its challenges :-)

$ foo=bar
$ echo "$foo"
bar
$ echo "'$foo'"
'bar'
$ echo '$foo'
$foo

So, your echo works because ' has no special meaning within "", but defaults write '$1/Contents/info.plist' MyVariable false will work neither in Terminal nor in Automator because the ' prevents any variable expansions ($1 literally stays $1).

Try defaults write "$1/Contents/info.plist" MyVariable false instead.

4
  • This worked in Automator, but the moment I saved the app and tried from there, it doesn't work. It looks like it's not processing the variable, and getting the entire path. Commented Apr 17 at 11:19
  • The action "Run Shell Script" encountered an error: "2024-04-17 04:22:21.595 defaults[35616:6995614] Could not write domain /Contents/info.plist; exiting" Commented Apr 17 at 11:23
  • But for some reason, if I convert it to a Quick Action, it works. It just will not work as an application. Commented Apr 17 at 11:29
  • According to the error message, $1 was empty/unassigned.
    – nohillside
    Commented Apr 17 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .