Apple - Why is OSX telling me I can't open a document from an unidentified developer?

This answer applies if you set the app for that particular document, not for all documents of that type (e.g. by using Get Info on the document, and changing the "Open with" pop-up menu, but not clicking the "Change All" button).

There are two critical pieces here. First, if you set a document to open in a particular app, what it actually does is attach some metadata to the file (think of it like sticking a post-it note onto the file) that says to open it with that particular app. Second, if a document is quarantined (because it was downloaded from the internet, or created by a sandboxed app, or some other reasons), it's considered untrusted, and the gatekeeper security policy will be applied to anything like executable in the file.

These two features can interact in an unfortunate way: that "open with" note is an instruction about what to do, and therefore (sort of) executable code, and therefore the gatekeeper security policy applies to it (even though you created the note, it's "part of" the untrusted file, and therefore untrusted). Thus, double-clicking a document (with "open with" metadata) can get you the untrusted app warning/error.

Fortunately, as long as you want all files of that type (.cs in this case) to open in the same app, there's a solution: in the Info window, Open with section, select the app you want (e.g. Visual Studio Code), and then click "Change all". This removes the metadata from the file, and instead makes an entry in your Launch Services preferences saying that you prefer to have files of that type open in that app. Since the setting is now a personal setting rather than a note attached to an untrusted file, the problem goes away.


The document is likely marked as executable.

You need to remove the executable bit from the file. This does not affect the file's contents, only how it is handled by the operating system. You can do this with the command line tool chmod:

chmod -x <path to file>

File Marked as Executable

All executable files pass through macOS's security checks. As this file is not a signed executable, the checks fail.

As this is a mistakenly marked-as-executable file, the ability to open bypassing the checks are disabled; there is no executable to actually launch.

This problem is fairly common when moving files between operating systems. Differences in the importance of file type bits effectively get lost in translation.


This is probably because the file was downloaded from the internet; Safari marks it as quarantined to make it harder for malware to execute.

You can test this easily by doing xattr <file> and checking if one of the output lines is com.apple.quarantine.

If it does, the solution is simply to do xattr -d com.apple.quarantine <file>. Note that executing that command for a file not in quarantine will give an error that the attribute was not present. So it is safe to just start with that; if the warning is given, look for another solution.