Spotlight search in NC #2: tags, XAs etc.

Questions, glitches, bugs and crashes
Post Reply
JayB
Posts: 183
Joined: Sun Jan 08, 2017 4:38 pm

Spotlight search in NC #2: tags, XAs etc.

Post by JayB » Fri Apr 02, 2021 9:37 pm

Split from the other topic… I think this is important enough to be put in its own topic.

It seems that Nimble Commander is unable to search for XAs like kMDItemUserTags with Spotlight, i.e. searching for "foo" works, but not "tag:foo". Any plans to implement expanded Spotlight search incl. tag/XA search functionality in NC?

User avatar
mike
Posts: 899
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: Spotlight search in NC #2: tags, XAs etc.

Post by mike » Sun Apr 04, 2021 8:36 pm

You can customise a query string via config: "filePanel.spotlight.format".
Config.json contains some explanation.
I have no plans to improve Spotlight support at the moment.

JayB
Posts: 183
Joined: Sun Jan 08, 2017 4:38 pm

Re: Spotlight search in NC #2: tags, XAs etc.

Post by JayB » Sun Apr 04, 2021 9:19 pm

Hmm… there aren't any explanations in the config.json. I assume I have to create something like this:

Code: Select all

{
    "filePanel": {
        "spotlight": {
        	"format": "foo"
        },
But I can't say how to modify foo to have an actual effect. (?)

User avatar
mike
Posts: 899
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: Spotlight search in NC #2: tags, XAs etc.

Post by mike » Sun Apr 04, 2021 9:34 pm

It's in the "original" version of Config.json:

Code: Select all

migun@Michaels-MBP-13-2020 Resources % cat /Applications/Nimble\ Commander.app/Contents/Resources/Config.json | grep -A 12 spotlight
        "spotlight": {
            /**
             * Search request formatting. #{query} will be replaced with entered search criteria.
             * There's an option to split input parameter string into substrings with spaces(" ") and use them separately.
             * To do so #{query1}, #{query2}, ..., #{query9} should be used, like the one below:
             * "kMDItemFSName == '*#{query1}*'cd && kMDItemFSName == '*#{query2}*'cd && kMDItemFSName == '*#{query3}*'cd && kMDItemFSName == '*#{query4}*'cd && kMDItemFSName == '*#{query5}*'cd && kMDItemFSName == '*#{query6}*'cd && kMDItemFSName == '*#{query7}*'cd && kMDItemFSName == '*#{query8}*'cd && kMDItemFSName == '*#{query9}*'cd".
             */
            "format": "kMDItemFSName == '*#{query}*'cd",
            
            /**
             * Maximum results count to fetch.
             */
            "maxCount": 1024

JayB
Posts: 183
Joined: Sun Jan 08, 2017 4:38 pm

Re: Spotlight search in NC #2: tags, XAs etc.

Post by JayB » Sun Apr 04, 2021 11:12 pm

Ah, thank you. So you can't input the kMDItem keys directly into NC's search field, which means you would have to load a different config every time you want to do an alternate search, right? E.g. like so… with the mv command substituting the main config for a prepared config that contains the search terminology for tags, i.e.

Code: Select all

"format": "kMDItemUserTags == '*#{query}*'cd"

Code: Select all

#!/bin/zsh

# ncspot

! [[ $* ]] && exit 1

searchtag=false
if [[ $1 == "--tag" ]] ; then
	searchtag=true
	shift
fi
searchterm="$*"

if ! $searchtag ; then
	osascript -e "tell application \"Keyboard Maestro Engine\" to do script \"NCSpotlight\" with parameter \"$searchterm\""
else
	supportdir="$HOME/Library/Application Support/Nimble Commander/Config"
	mv "$supportdir/Config.json" "$supportdir/bak.Config.json"
	mv "$supportdir/tags.Config.json" "$supportdir/Config.json"
	sleep 1
	osascript -e "tell application \"Keyboard Maestro Engine\" to do script \"NCSpotlight\" with parameter \"$searchterm\""
	sleep 1
	mv "$supportdir/Config.json" "$supportdir/tags.Config.json"
	mv "$supportdir/bak.Config.json" "$supportdir/Config.json"
fi

exit

Post Reply