1

This question was previously asked here: https://stackoverflow.com/questions/74808784/after-switching-default-shell-command-file-just-opens-terminal

However, I have found no reason for the behavior, so I'm re-asking it here so that maybe someone more knowledgeable about fish can figure out a more satisfying answer.

Here's the problem: .command files have long been used on macOS to be able to quickly double-click and execute a script in the Terminal. Normally, when you double-click a .command file, it opens a new Terminal window and then immediately executes the script.

The Terminal also has a preference to set a default shell. For example, I've downloaded the self-contained fish app and then set this Terminal preference [Terminal menu --> Preferences --> General --> Shells open with: --> Command (complete path):] to the following: /Applications/fish.app/Contents/Resources/base/usr/local/bin/fish

Now, however, when I double-click on .command files, the Terminal simply opens with a new fish shell and does nothing. Why? Is there a way to fix this?

Here's the entirety of a sample .command file that works fine when the Terminal's preference is set to the default shell of zsh. Note that yes, execute permissions have been set on this file:

#!/bin/zsh
/Applications/Chrome.app/Contents/MacOS/Google\ Chrome --guest
3
  • Instead of a .command file, how about using an AppleScript that uses do shell script ...? Commented Sep 13 at 20:21
  • 2
    Since this is so MacOS-specific, Ask Different might be a better place to ask. Commented Sep 13 at 20:22
  • Is there perhaps a security subsystem in MacOS that thinks .command files may be executed by zsh but not by other shells? Commented Sep 13 at 20:29

1 Answer 1

1

This is a bug in macOS Terminal and not related to fish-shell. For example, if you set "Shells open with" to /opt/homebrew/bin/zsh, or even point it at a symlink to /bin/sh, the bug reproduces as you describe.

iTerm2 does not have this bug, so as a workaround you can try switching "command" files to it:

  1. Select the 'command' file in Finder
  2. Press ⌘-i to "Get Info" on it
  3. Change "Open With" to iTerm2

You can set it for all "command" files if you like.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.