I sometimes use an external SSD with macOS Sierra on it, in conjunction to my current internal drive which has macOS Sierra running on it.

One annoying thing about Spotlight is that whenever I search something in it for example when I'm running from my external drive is that I get results from both my external and internal drive, which is something I don't want.

When booted into my external drive, I tried creating a Spotlight exception for internal drive. However, it seems that if I do that, an exception is created for my internal drive even when I boot into my internal drive. Thus, it seems as though the Spotlight exclusions are bound by the laptop, not the drive – meaning that my internal drive will be excluded from spotlight results no matter which external drive I boot up from.

Is it possible to create a Spotlight exception for my internal drive when I am running from my external drive, and likewise an exception for my external drive when I am running from my internal drive?


You could have a script that runs at startup that employs the technique suggested in this post https://apple.stackexchange.com/a/91759/183505

When booting from DriveA (when you want to disable spotlight indexing for External DriveB) you could execute :

touch /Volumes/DriveB/.metadata_never_index

When booting from external DriveB and you want to re-enable spotlight perhaps you could have your startup script execute:

rm /Volumes/DriveB/.metadata_never_index

The linked post also lists other ways to programatically alter the spotlight exclusions.

Here are some ways to add a script that will launch at login : https://stackoverflow.com/questions/6442364/running-script-upon-login-mac

Good luck!

Edit : Method using bash scripts and plist files

First create a startup script. I chose to create one at ~/script.sh

Make sure it's executable chmod +x ~/script.sh

Script for OS that wants to hide a drive from spotlight

flagRemoved=".ney_the_index"  # a new name

# if flag exists rename it.
if [ -a "$flagLocation/.metadata_never_index" ]; then 
    mv "$flagLocation/.metadata_never_index" "$flagLocation/$flagRemoved";

Script on the OS that wants to index the drive


if [ -a "$flagLocation/$flagRemoved" ]; then
    mv "$flagLocation/$flagRemoved" "$flagLocation/.metadata_never_index"

if [ ! -a "$flagLocation/$flagRemoved" ] || [ ! -a "$flagLocation/.metadata_never_index" ] ; then
    touch "$flagLocation/.metadata_never_index"

Create a plist file ~/Library/LaunchAgents/com.user.loginscript.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

Test it by loading and unloading it:

launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist
  • Seems like this is the best way to do it. I was hoping for something more "native" in a way, but this should be quite reliable. Thank you. – Skeleton Bow Feb 15 '17 at 13:21
  • I want to mention a problem I'm facing trying to implement this: the rm command requires that I run it using sudo. I'm using the first method in the SO link you posted. Would you happen to have any suggestions for that? Do I need to use the launch daemon method to overcome this? – Skeleton Bow Feb 15 '17 at 14:24
  • I updated my answer with a slightly hacky solution. – hapi Feb 17 '17 at 2:10
  • 2
    If DriveToHide has spaces, then your scripts, as currently written, will fail. If you are going to test with [ ... ] then double quote the variables to prevent blobbing and word splitting. Or use [[ ... ]] to test, then double quoting isn't necessary. – user3439894 Feb 17 '17 at 2:33
  • Nice! thanks user3439894. I updated the answer to reflect your suggestion. – hapi Feb 17 '17 at 3:00

Apologies for the new answer (not enough rep to comment as I'm new here)

@hapi - I may be confused, but are the scripts the wrong way round?

Script for OS that wants to hide a drive from spotlight: renames .metadata_never_index

Script on the OS that wants to index the drive: creates .metadata_never_index

I thought the presence of .metadata_never_index on the volume meant Spotlight ignored it?



Whereas the other answer is a good method to do it, it can inadvertently cause problems and may not be 100% reliable. A better method would be to use Alfred, as it is more flexible than Spotlight, on the external OS.

  • How would you use Alfred for this? – Matt Sephton Jan 2 '18 at 19:34
  • Good question. I wish I remembered how. I believe I was talking about the way that you can exclude folders from the Alfred search without having to use exclusion method which was suggested in the other answer. – Skeleton Bow Jan 2 '18 at 22:05

You must log in to answer this question.

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