59

I used brew to install MacVim and it put it in /usr/local/Cellar/macvim/7.3-61/MacVim.app

I would like to be able to go to spotlight and type MacVim to launch the app. I tried creating a symlink in the Applications directory to /usr/local/Cellar/macvim/7.3-61/MacVim.app. But that doesn't seem to show up in Spotlight. I set the executable bits on the symlink. open MacVim.app from the command line works. How can I get MacVim to show up in Spotlight search?

9
  • 2
    Spotlight doesen't look inside hidden folders and apparently doesen't work for aliases either. Do you use spotlight to launch apps? If so I must recomend alfredapp.com. I use it and its great. Faster than spotlight!
    – kevin9794
    Aug 31, 2011 at 2:25
  • Thanks. I installed alfred and added the MacVim folder to the search scope. Im in much better shape.
    – m_sharp
    Aug 31, 2011 at 5:00
  • 4
    OK, I figured it out. If I make an alias to /usr/local/Cellar/macvim/7.3-61/MacVim.app, Spotlight will index it. For more on aliases, check out switchingtomac.com/tutorials/creating-aliases-in-mac-os-x
    – m_sharp
    Aug 31, 2011 at 5:07
  • 3
    Welcome to Ask Different! If you found a solution, please post it as an answer so it's easier for others with the same problem to see what helped. Please take a look at the FAQs for more info. Thanks. Nov 11, 2011 at 23:10
  • 2
    To clarify @m_sharps's comment, it appears that Spotlight will index aliases, but not symbolic links (ln -s).
    – zourtney
    Aug 31, 2012 at 15:55

11 Answers 11

39

In the Finder, press CommandShiftG for Go to the Folder. Type /usr/local/Cellar/macvim/7.3-61/ and press return. Select the file (actually a folder) MacVim.app Press CommandL for Make Alias. Depending on permissions, you may be prompted for an administrator password here.

Press CommandN to create a New Finder Window. Press CommandShiftA to go to the Applications folder in that window.

Drag the newly created alias from the window in which it was created to the window containing the Applications folder. Rename the alias so it no longer ends in " alias".

7
  • 2
    I followed your steps and MacVim shows up in spotlight. However when trying to launch MacVim from spotlight, I get an error message "Item MacVim is used by OS X and can't be opened".
    – m_sharp
    Dec 12, 2011 at 5:32
  • Hmmm. How do you ordinarily launch MacVim when not using Spotlight? Do you get an error message then?
    – Daniel
    Dec 12, 2011 at 6:26
  • Maybe spotlight can't launch it because it doesn't have the permissions to access /usr/local/ or something.
    – styfle
    Jan 12, 2012 at 4:05
  • I got this to work by first changing the permissions on /usr/local/Cellar with 'sudo chflags nohidden /usr/local/Cellar' (I actually did this for /usr /usr/local and /usr/local/Cellar). Then I used Finder to create an alias for MacVim (the one in Cellar). Then I moved the alias to my Applications folder. Spotlight now finds MacVim (look at the bottom of its list until you open it once).
    – Chris
    Oct 18, 2014 at 17:32
  • 1
    This should work for now but break when brew updates MacVim. zim's way should persist through updates because it goes through homebrew's symlink to the app.
    – Jacktose
    Sep 13, 2016 at 2:12
13

The alias method did not work for me. A better option is to use Automator to create an Application that runs a shell script:enter image description here

Also, linking directly to the MacVim.app in the Cellar directory like some of the other answers suggest binds you to a specific version. If brew upgrades MacVim, your link will still point to the old version. Rather, you should use:

open /usr/local/opt/macvim/MacVim.app $@

as this location is automatically symlinked by brew to the most recent version.

This worked great for me. I save the Automator file in iCloud so I can conveniently add the app on other machines.

6
  • This seems like the most robust solution. What is the $@ for?
    – Jacktose
    Sep 13, 2016 at 1:45
  • 1
    The $@ represents the arguments passed to the script. In this case, any args passed to the script are being forwarded to the MacVim.app (i.e. file names, options, etc.) See this answer about special shell variables.
    – zim
    Sep 13, 2016 at 4:56
  • Ah, thanks. It's really hard to google $@. Will that actually do anything in this case, though, since the script is just being run by selecting the app?
    – Jacktose
    Sep 13, 2016 at 5:08
  • 1
    Yeah, it's helpful, for example, if you use the Open with command on a file in Finder. The app will be started with the file path as the first argument. Or if you set MacVim as the default app for a file type, .txt for example - then double clicking a .txt file will start MacVim with the selected file as the first arg.
    – zim
    Sep 13, 2016 at 15:14
  • This is great, thanks -- I think the argument should be in double quotes though ("$@"), to handle files with spaces in their names. You can see the problem if you run this in the terminal: function foo { printf '%s\n' $@; }, then foo "this is one file.txt". Jun 24, 2022 at 16:07
4

The way I've solved this is using a shell script and appify.

For example make a script with a text editor that contains

#!/bin/bash

/usr/local/Cellar/macvim/7.3-61/MacVim.app

Then get appify - http://git.abackstrom.com/appify.git

Run appify on the shell script and it will make an application you can put in /Applications that will invoke MacVim. This will show up in spotlight.

2
  • 1
    If you're going to do it this way, just create an Automator app to run the script.
    – ocodo
    Oct 25, 2014 at 14:11
  • Yes @Slomojo, that proved to be the easiest approach. I created a shellscript that starts the App (in my case libreoffice) and put it in /usr/bin. Then I used automator to just invoke the script and saved the Automator created App in my Applications folder with the name I wanted to use in Spotlight. Absurd.
    – atripes
    Jan 22, 2015 at 12:42
4
  1. Symbolic links (ln -s) did not work well for me, it did not appear that Spotlight would see this as an application.

  2. Making a finder alias (as described by Daniel) worked better regarding launching from Finder, but did not when using Finder Open With..., the alias would remain grayed out.

In particular, like mentioned in other comments here, I also wanted MacVim to be available when using Open With... from Finder, but with either the symbolic link or Finder alias, MacVim would remain grayed out.

What worked for me was the simple Automator script (as zim described), with the "Run Shell Script" command. The only thing I had to do differently than what zim showed in his answer is adding the -a parameter to open:

open -a /usr/local/opt/macvim/MacVim.app $@

Without the -a, when used with "Open With...", MacVim would launch, but also the parameter filename would open with whatever its default application was -- so I would get both MacVim with empty document AND TextEdit with the file I had selected to open (rather than MacVim with my selected file opened).

The automator script can be copied or aliased to the Applications folder. I also changed my automator script's icon to MacVim's icon by copying & pasting the icon from the Finder's Get Info popups.

3

To keep things nice and scriptable, you can use osascript to run a little AppleScript and create your alias automatically.

osascript <<END

  set macvim to POSIX file "/usr/local/Cellar/macvim/7.3-61/MacVim.app" 
  set applications_folder to POSIX file "/Applications"

  tell application "Finder"
    make alias file to macvim at applications_folder
  end tell

END
3
  • This actually worked, unlike many osascript one-liners I've found in various places. Dec 14, 2014 at 10:14
  • 1
    I would recommend actually moving the MacVim app to Applications. Or installing it via brew cask. Aliases do index in spotlight, but they are ranked annoyingly low.
    – ocodo
    Dec 14, 2014 at 13:01
  • Thanks. I have noticed that it's hard to get Spotlight to choose my MacVim alias. Dec 14, 2014 at 21:48
2

After trying several of the suggested solutions, the best thing that worked for me was to copy the app from the Homebrew Cellar to the applications directory:

cp -r /usr/local/Cellar/macvim/7.3-66/MacVim.app /Applications/

Spotlight found it instantly.

2

For those who use homebrew to install macvim (totally recommended)

Run the following after install

brew linkapps macvim
3
  • 1
    Unfortunately, these don't show up in Spotlight.
    – Jacktose
    Sep 13, 2016 at 1:16
  • but you can make an alias to the MacVim link in /Applications directory, the alias is picked up by Spotlight. Dec 21, 2016 at 21:43
  • 2
    Unfortunately 'brew linkapps' does not exist any more, and it is not replaced.
    – Katarzyna
    Apr 11, 2018 at 2:49
1

Best way doing it come from homebrew it self

osascript -e 'tell application "Finder" to make alias file to POSIX file "/usr/local/Cellar/macvim/7.3-61/MacVim.app" at POSIX file "/Applications/"'

here is the reference:

0

The simple act of installing homebrew allowed me to create a symlink to Sublime Text. Perhaps you are needing more.

Install homebrew here if you have macOS

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

and then from command line (assuming ST is installed)

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

-1

This doesn't directly answer the question, but instead inverts the install process so that MacOS will find MacVim like any app.

  1. If you already installed macvim with brew, uninstall it with brew uninstall macvim.
  2. Download MacVim and install the .dmg like any application.
  3. Add an alias to your .bash_profile:
# Create a MacVim alias if it's installed as MacOS application
[ -x "$(command -v /Applications/MacVim.app/Contents/MacOS/Vim)" ] \
  && alias vim='/Applications/MacVim.app/Contents/MacOS/Vim'

Now the MacVim GUI will work like any MacOS app (including with Spotlight), and the next time you open the terminal, the command vim will open MacVim in the terminal instead.

-2

Sounds like you could do the following from the Terminal.

$ ln -s /usr/local/Cellar/macvim/7.3-61/MacVim.app /Applications

You might have to use sudo to put the symlink in the /Applications directory.

3
  • 3
    Spotlight treats symlinks to "system files" as system files, so they aren't listed in normal results. Aliases are though.
    – Lri
    Jan 17, 2012 at 2:43
  • Any way to create an OS X alias programmatically in Bash? Aug 16, 2012 at 14:50
  • @MathiasBynens - see my answer, a little AppleScript will do it.
    – ocodo
    Oct 25, 2014 at 14:09

You must log in to answer this question.

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