8

IntelliJ IDEA 2020 can (finally!) simply open a file to be edited, without a project being involved. This is called LightEdit mode.

At this point in a JetBrains video, we see the host platform's file manager app opening a file via IntelliJ while noting that all such files should be opened using that same tool.

No "IntelliJ" application to choose

The problem for me is that I am a happy user of JetBrains Toolbox app to automatically install, upgrade, and open IntelliJ. So in my "Applications" folder on macOS, I have no "IntelliJ" application to choose in the Mac Finder when trying to open a file.

Is there some other way or trick to getting the Finder to know to open files with IntelliJ? And preferably with the latest version, as I believe Toolbox may keep around the older versions.

Basically, I am asking the same as this Question, How to make available “open this project in IntelliJ IDEA” option in Windows context menu, if IntelliJ IDEA has been installed via JetBrains Toolbox?, but for macOS instead of MS Windows. The Answer on that other Question is Windows-specific.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
  • For the file you want to open, do `⌘ + i` (command + i, which is "get info") in Finder, then "Open with...", scroll down to the bottom of the list of applications and select "Other", then select the app you want to associate with the file and then "Change all...". – l'L'l Jan 25 '21 at 05:36
  • 1
    @l'L'l As I said in the Question, there is no "IntelliJ" app listed in my Applications folder because I am a user of JetBrains Toolbox. You said "select the app" but there is *no app for me to choose*. I added a heading to make this more obvious. – Basil Bourque Jan 25 '21 at 06:11
  • According that page you linked: "You can find the script for running IntelliJ IDEA in the installation directory under `bin`", so it would seem you could associate the file with it right? If you normally launch it from the command line you can easily make a shell script that acts as an executable by saving it as `.command`. – l'L'l Jan 25 '21 at 06:26

2 Answers2

6

As a Toolbox user you still have access to the "generated shell scripts" (/usr/local/bin/idea, or things like /usr/local/bin/phpstorm, /usr/local/bin/pycharm, etc for individual applications).

But, these are shell scripts, and cannot be used for this because they lack the application identifiers needed by the OS for launching apps.

What you can do is wrap any of this with an Automator application. By wrapping the shell script directly, it should remain updated (since the shell script is itself a Toolbox generated wrapper that points to the latest installed version).

To do so:

  1. Open Automator and click on the "new document" button.
  2. Select "Application".
    enter image description here
  3. Add a "Run shell script" action from the library:
    enter image description here
  4. Change the "pass input" dropdown from "to stdin" to "as arguments".
  5. Create a script similar to this this (replace phpstorm with idea or whatever IDE you have installed):
    for file in "$@"
    do
        /usr/local/bin/phpstorm -e "$file"
    done
    
  6. Save the application somwhere, with a descriptive name:
    enter image description here

Once that one is saved, you'll be able to use it to launch files from Finder, or even set it as default for a file type:

enter image description here

yivi
  • 42,438
  • 18
  • 116
  • 138
  • My apologies for the Spanish language screen-shots. Would appreciate if someone could replace them with English language ones. – yivi Jan 25 '21 at 08:44
3

Use the app's menu: IntelliJ IDEA -> Preferences -> Editor -> File Types

Then press the Associate File Types with IntelliJ IDEA button.

enter image description here

A window will open with file groups you could choose from, and then press the OK button, then Apply and another OK.

After this, a MacOS restart is required.

Aurel Branzeanu
  • 535
  • 1
  • 7
  • 18
  • 1
    If the file type doesn't appear in the popup (like `*.log`), create the file type first. Make sure to hit Apply so it will show up in the popup. – Noumenon Jun 26 '23 at 05:20