sveinbjornt / Platypus

Create native Mac applications from command line scripts.
https://sveinbjorn.org/platypus
BSD 3-Clause "New" or "Revised" License
2.8k stars 170 forks source link

app starts from Terminal but not Finder #220

Open franzinc opened 2 years ago

franzinc commented 2 years ago

This took me a long time to figure out, so I'm filing this so others know about it.

The script that I've used for a long time has always had this near the top:

exec > "$HOME/.app.log"
exec 2>&1
set -x
# lots more stuff after the above 2 exec's will now be recorded in $HOME/.app.log

Turns out, if I include those, the app starts fine from Terminal but not from Finder. It used to work starting from Finder, but at some point in the last few months it just stopped working. I'm using /bin/zsh as the SHELL, but I believe it fails with /bin/bash, too.

I suspect this is due to security issues in macOS, but I have no idea.

artcs commented 2 years ago

Most probably $HOME isn't set, so you're trying to write to /.app.log in the root directory. You could try "~/.app.log" instead. If you need more environment settings, try setting -l als interpreter arg (see here, should work with zsh the same way), so the shell acts like being invoked as a login shell.

artcs commented 2 years ago

From zsh manpage:

HOME <S>
              The  default argument for the cd command.  This is not set auto-
              matically by the shell in sh, ksh or csh emulation […]

Do you use /bin/zsh explicitly (under Script Type) or is zsh invoked with /bin/sh?

franzinc commented 2 years ago

I'm 100% sure this is not the problem because the file in $HOME had stuff in it. I had set -x just after the exec's and the last command, that started the app, was in the log file.

I used -p /bin/zsh to the command line version.

artcs commented 2 years ago

Ok, was just a blind guess. FWIW: Your snippet works fine here on MacOS 10.13 with sh (bash) and zsh from Finder (created from the app, I don't use the command line version), so I cannot reproduce your issue. Good luck.

franzinc commented 2 years ago

I'll play around and see if I can make a reproducible test case.