Skip to content

Instantly share code, notes, and snippets.

@umjammer
Last active October 1, 2022 13:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umjammer/068c8ab74f6afa296e038d4ce9911be5 to your computer and use it in GitHub Desktop.
Save umjammer/068c8ab74f6afa296e038d4ce9911be5 to your computer and use it in GitHub Desktop.

How to enable spotlight indexing for Google Drive again

Situation

  • after Google Drive.app update version 52.0.6.0
  • search from finder doesn't work
  • mdutil -i on /Volumes/GoogleDrive never work
    • returns Indexing and searching disabled.
  • https://apple.stackexchange.com/a/424445
    • change_gdrive_smb_port.py seems not work for version 52.0.6.0
  • localhost is sometimes mounted on (/Volumes/Google Drive). and i wonder why it sometimes disappears?

Solution

create and mount an indexable volume

  • check localhost is mounted
    • found in finder sidebar
    • or use mount command
$ mount
 :
//DRIVE@localhost:49626/Google%20Drive on /Volumes/GoogleDrive (smbfs, nodev, nosuid, nobrowse, mounted by nsano)

this case localhost is not mounted.

  • if localhost is mounted, you can see like below
$ mount
 :
//sorry_i_forgot_here_but_very_long_name._smb._tcp.local on /Volumes/Google Drive (smbfs, nodev, nosuid, mounted by you)
//DRIVE@localhost:49626/Google%20Drive on /Volumes/GoogleDrive (smbfs, nodev, nosuid, nobrowse, mounted by you)
  • if localhost is not mounted. mount it by your self
    • finder >> move >> connect server >> smb://localhost:port
    • or osascript -e "try" -e "mount volume \"smb://localhost:49626\"" -e "end try"

re-index

  • after mounting localhost, like below
$ mount
 :
//DRIVE@localhost:49655/Google%20Drive on /Volumes/GoogleDrive (smbfs, nodev, nosuid, nobrowse, mounted by you)
//DRIVE@localhost:49655/Google%20Drive on /Volumes/Google Drive (smbfs, nodev, nosuid, mounted by you)

why one is indexable (/Volumes/Google Drive you mounted) and the other (/Volumes/GoogleDrive) is not?

  • remove old index (when the port number is same)
    • we need to do this when the app version is updated
$ sudo ls -l /private/var/db/Spotlight-V100/LocalVolumes/
total 0
drwx------  4 root  wheel  128 10 13 19:17 smb%3A%2F%2FDRIVE@localhost%3A49223%2FGoogle%2520Drive
$ sudo rm -rf /private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A49223%2FGoogle%2520Drive           
  • re-index
    • use mount point localhost (found in finder or you mounted)
$ mdutil -i on /Volumes/Google\ Drive 
/System/Volumes/Data/Volumes/Google Drive:
	Indexing enabled. 
$ mdutil -E on /Volumes/Google\ Drive 

after restarting Googe Drive.app

  • you don't need to re-index
  • check new port number
$ mount
 :
//DRIVE@localhost:49319/Google%20Drive on /Volumes/GoogleDrive (smbfs, nodev, nosuid, nobrowse, mounted by nsano)
  • rename index folder
    • change port number
sudo mv /private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A49655%2FGoogle%2520Drive /private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A49319%2FGoogle%2520Drive
  • mount indexable volume again

    • finder >> move >> connect server >> smb://localhost:port
  • it works!

for better QOL

  • smb port is chaged evry time Google Drive.app restart, we need to do this everytime after restart.
  • indexing caches huge amount of files. so before indexing, it's better to limit cache size.
    $ sudo touch /Library/Preferences/com.google.drivefs.settings
    $ sudo defaults write /Library/Preferences/com.google.drivefs.settings ContentCacheMaxKbytes -int 100000
  • limit indexing area using "system settings >> spotlight >> privacy" for reducing google drive and network load.

Env

  • MacOS BigSur
  • GoogleDrive.app 52.0.6.0 ~ 55.0.3.0
  • streaming mode
@umjammer
Copy link
Author

umjammer commented Nov 29, 2021

#!/bin/bash

echo -e '\033[37;44m'"\033[1m"---- port ----"\033[0m";

PORT=$(mount | grep GoogleDrive | grep -o -E '\d{5}')
echo PORT: $PORT

echo -e '\033[37;44m'"\033[1m"---- mount ----"\033[0m";

if [ ! -d "/Volumes/Google Drive" ]; then
  osascript -e "try" -e "mount volume \"smb://DRIVE@localhost:$PORT\"" -e "end try"
else
  echo already mounted
fi

mount | grep Google

echo -e '\033[37;44m'"\033[1m"---- dir ----"\033[0m";

DIR=$(sudo ls /private/var/db/Spotlight-V100/LocalVolumes/)
echo DIR: $DIR

if sudo [ ! -d "/private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A$PORT%2FGoogle%2520Drive" ]; then
  sudo mv /private/var/db/Spotlight-V100/LocalVolumes/$DIR /private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A$PORT%2FGoogle%2520Drive && echo renamed || echo rename failed
else
  echo already exists
fi

sudo ls -la /private/var/db/Spotlight-V100/LocalVolumes/ | grep Google

echo -e '\033[37;44m'"\033[1m"---- exclude ----"\033[0m";

for d in \
    "/My Drive/Documents" \
    "/My Drive/YouWantToExclude" \
                  :
;
do
  sudo /usr/libexec/PlistBuddy -c "Add :Exclusions:0 string $d" /private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A$PORT%2FGoogle%2520Drive/VolumeConfiguration.plist
done

sudo /usr/libexec/PlistBuddy -c "Print :Exclusions" /private/var/db/Spotlight-V100/LocalVolumes/smb%3A%2F%2FDRIVE@localhost%3A$PORT%2FGoogle%2520Drive/VolumeConfiguration.plist

echo -e '\033[37;44m'"\033[1m"---- enable ----"\033[0m";

string=$(mdutil -s /Volumes/Google\ Drive | tail -1)
if [[ $string == *"enabled"* ]]; then
  echo already enabled
else
  mdutil -i on /Volumes/Google\ Drive
fi

mdutil -s /Volumes/Google*

@umjammer
Copy link
Author

umjammer commented Sep 30, 2022

FINALLY WE CAN SEARCH ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰

https://support.google.com/drive/thread/148373461?hl=en&msgid=170753913

implementation method is the same as i mentioned before!

https://support.google.com/drive/thread/148373461?hl=en&msgid=150326177

version 64.0.4.0

no search no google

@umjammer
Copy link
Author

umjammer commented Oct 1, 2022

BUT TOO SLOW ๐Ÿ˜ฉ๐Ÿ˜ฉ๐Ÿ˜ฉ

version 64.0.4.0

https://support.google.com/drive/thread/148373461?hl=en&msgid=173758917

@umjammer
Copy link
Author

umjammer commented Oct 1, 2022

LOST ALL TAGS โ†’ just in search result

version 64.0.4.0

over 100 items i tagged...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment