2

The open command on macOS usually opens files in their default application.

On my new M1 Pro though it just always says "Unsupported OS"

❯ open test.txt
Opening 'test.txt' ...
Unsupported OS.

Any ideas why this could be happening?

To be clear it does not matter what I try to run be it an app or a file:

❯ open -a TextEdit
Opening '-a TextEdit' ...
Unsupported OS

It does not matter what the file type is either.

Nothing can be run with open no matter what the arguments are I will get the same response.

3
  • 7
    What is the default application for .txt?
    – nohillside
    Jun 26 at 11:47
  • 2
    The application to be used for .txt files most likely is the culprit. Jun 26 at 13:52
  • I used a text file as an example only it doesn't matter what the file type is or what application is the default. Added more details to the question to clarify.
    – Brad
    Jun 28 at 1:49

2 Answers 2

2

Try the open application alone to see if it is the culprit (it sounds like it is).

Charlie:~ sfederman$ open
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [-u URL] [filenames] [--args arguments]
Help: Open opens files from a shell.
      By default, opens each file using the default application for that file.
      If the file is in the form of a URL, the file will be opened as a URL.
Options:
      -a                    Opens with the specified application.
      -b                    Opens with the specified application bundle identifier.
      -e                    Opens with TextEdit.
      -t                    Opens with default text editor.
      -f                    Reads input from standard input and opens with TextEdit.
      -F  --fresh           Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
      -R, --reveal          Selects in the Finder instead of opening.
      -W, --wait-apps       Blocks until the used applications are closed (even if they were already running).
          --args            All remaining arguments are passed in argv to the application's main() function instead of opened.
      -n, --new             Open a new instance of the application even if one is already running.
      -j, --hide            Launches the app hidden.
      -g, --background      Does not bring the application to the foreground.
      -h, --header          Searches header file locations for headers matching the given filenames, and opens them.
      -s                    For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.
                            Otherwise the highest versioned SDK in each platform is used.
      -u, --url URL         Open this URL, even if it matches exactly a filepath
      -i, --stdin  PATH     Launches the application with stdin connected to PATH; defaults to /dev/null
      -o, --stdout PATH     Launches the application with /dev/stdout connected to PATH;
          --stderr PATH     Launches the application with /dev/stderr connected to PATH to
          --env    VAR      Add an enviroment variable to the launched process, where VAR is formatted AAA=foo or just AAA for a null string value.

Also, try this (below is on an M1 Max):

Charlie:~ sfederman$ which open
/usr/bin/open
Charlie:~ sfederman$ file /usr/bin/open
/usr/bin/open: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64
- Mach-O 64-bit executable x86_64] [arm64e:Mach-O 64-bit executable arm64e
- Mach-O 64-bit executable arm64e]
/usr/bin/open (for architecture x86_64):    Mach-O 64-bit executable x86_64
/usr/bin/open (for architecture arm64e):    Mach-O 64-bit executable arm64e

If yours are somehow different, than you may need to either find a new open executable, or reinstall the OS.

1
  • 1
    which open showed it is not the standard open command. 🤦🏻‍♂️ A tools repo I was using placed a wrapper for open in my path that was also doing an OS check and failing.
    – Brad
    Jun 28 at 4:44
6

First thing is to open the app you want to see these files.

open -a TextEdit

Or Xcode or another app you know can open text files.

Once you have an app that opens, pass the file after the name of the app.

open -a TextEdit file.txt

Once that works, open the folder containing that text file and inspect the finder contextual menu and perhaps refresh the “Always open with” binding for that file type. You can use the file and mdls commands to examine the file in case the .txt is not representative of the actual file type. Sometimes text files are not simply a text file, so check out these metadata keys:

kMDItemContentType = "public.plain-text"
kMDItemContentTypeTree = (
kMDItemKind = "Plain Text Document"

Lastly if open itself is throwing the error, I would check if there is an error code we can look at as well as the code signing is still correct for that:

/usr/bin/open -a Finder
echo $?
codesign -vvvv -R="anchor apple" /usr/bin/open

The last should show a valid program passing all checks:

/usr/bin/open: valid on disk
/usr/bin/open: satisfies its Designated Requirement
/usr/bin/open: explicit requirement satisfied

You likely have a new open program in your path or a function - since you should not get the error you did Opening '-a TextEdit' ... as the open program should parse the -a switch and not spit it back to you...

% type open
open is /usr/bin/open
2
  • It's nothing to do with the file type or its default application. Obviously, test.txt is a text file I created to show an example. It doesn't matter what I try to run, be it an app or a file I get the same response. I'll add your example to my question to clarify.
    – Brad
    Jun 28 at 1:41
  • 1
    Aah - so that’s definitely a twist. It's like you aren't getting the proper open program. Have you a recent backup? If so, I would reinstall the OS on top of your system. If not, you might have to go back over changes you did recently or potential modifications to your shell. Are you using zsh on macOS Monterey @Brad ?
    – bmike
    Jun 28 at 2:35

You must log in to answer this question.

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