https://github.com/mhinz/spotlight-cli
Command-line tool for Spotlight.
https://github.com/mhinz/spotlight-cli
macos osx shell-script spotlight
Last synced: 4 months ago
JSON representation
Command-line tool for Spotlight.
- Host: GitHub
- URL: https://github.com/mhinz/spotlight-cli
- Owner: mhinz
- License: mit
- Created: 2016-10-08T18:06:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-08-10T19:20:20.000Z (almost 4 years ago)
- Last Synced: 2025-04-12T14:14:37.497Z (about 1 year ago)
- Topics: macos, osx, shell-script, spotlight
- Language: Shell
- Homepage:
- Size: 28.3 KB
- Stars: 37
- Watchers: 6
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
```
$ spot
Spotlight CLI.
If a command takes a [path], the results will be restricted to that directory.
apps Installed applications.
attr Attributes that can be used with "spot ".
author [path] Files from author.
ext [path] Any files with that extension.
$ spot ext pdf ~
file [path] Find files.
$ spot file vimrc ~/dotfiles
group [path] All files from user.
$ spot group $GID /etc
size [path] Find all files of a certain size in bytes.
Or (k)ilobytes, (m)egabytes, (g)igabytes.
$ spot size '>=' 1g ~
text [path] Find files containing text.
$ spot text 'ascii porn' ~
user [path] All files from user.
$ spot user $UID /var
Get all attributes for that path.
$ spot ~/fancy.gif
[path] Generic query. Supports any attributes from "spot attr".
See link at the bottom for the syntax.
$ spot foo
$ spot 'kMDItemMusicalGenre == *Metal*' /data/music
The Spotlight query syntax explained:
https://developer.apple.com/library/mac/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/QueryFormat.html
```
It's also fiendishly easy to add new commands to spot. For adding a command
"music", simply add an executable shell script called "spot-music" to your
$PATH:
```sh
#!/usr/bin/env bash
# The following line is optional and outputs a small reminder,
# if not enough arguments were given to the "music" command.
required $# ''
mdfind "kMDItemMusicalGenre == $1"
```
Using this, you can simply list all songs of a certain genre:
```
$ spot music Metal
$ spot music "Alpine folk music"
```
You could also change spot-music to take a second optional argument, to restrict
the matches to a certain directory:
```sh
#!/usr/bin/env bash
required $# ''
genre=$1
dir=$2
mdfind "kMDItemMusicalGenre == $genre" ${dir:+ -onlyin "$dir"}
```
Now, you can also use it like this:
```
$ spot music Metal ~/music
```