0

I want to select an application installed from Homebrew for dealing with files of a certain type. At first I discovered that the "Open with..." dialog won't even show /opt and other directories. So I found a thread here that suggests running this:

$ defaults write com.apple.Finder AppleShowAllFiles YES
$ killall Finder

OK, I did that. Now I can navigate to the directory with the applications under /opt but when I come to the list of binaries there they are "grayed out" so I can't select them. I selected Enable: All Applications but it doesn't make a difference. How can I make Finder just do the right thing? Also, sometimes I'd want to use a command line app. In other OSes sometimes you can associate the filetype with something like:

Terminal -c foobar %s

Where "Terminal" is any given console and %s is the file to open.

The file I want to associate with the filetype is a symlink if that matters.

What is the way to do this on Mac?


Edit: is there a shell script or set of steps for creating an ersatz .app directory, enough to make Finder see it?

3
  • Are the "applications" in /opt actual GUI apps (i.e. directories with a .app suffix, with a Contents directory inside that, and in Contents an Info.plist, MacOS and Resources subdirectories, etc)? Or are they command-line utilities, or something else? Oct 14 at 0:32
  • Just as an aside, command+shift+. does the same thing as the defaults write command you mentioned.
    – Ezekiel
    Oct 14 at 0:36
  • @GordonDavisson no they were just naked binaries. Which I have learned ought to be clothed in an app directory.
    – Lucky
    Oct 14 at 16:40
0

You cannot assign an executable directly to handle opening files in Finder. It does not matter where it's installed. This is because the system expects applications to present as .app bundles.

To run an executable with a file, you should run it from the command line. There are ways to run it from the right-click menu using Automator or Shortcuts.

In Automator, create a Quick Action. Configure it to receive "files or folders". Add a "Run Shell Script" that passes input as arguments (or stdin if you are familiar and prefer that). You can use $@ for all the files or $1-$n for specific files.

dosomething $1

In Shortcuts, check "Use as Quick Action" in the sidebar and configure it to receive files. Use the same contents of a Run Shell Script action as in the Automator example.

Either of these will show up in the Services menu, which is visible at the bottom of the right click menu in finder.

2
  • Do you know of a shell script to create an application bundle, or must one pull in xcode and related tools to do that?
    – Lucky
    Oct 14 at 16:39
  • You technically don't need Xcode, but it'll be much easier. You could build a proper .app that recognizes when it's opened with a file and runs the executable for you.
    – Ezekiel
    Oct 14 at 16:41

You must log in to answer this question.

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