Parsing options in com.apple.Spotlight

jrserapio
Contributor

Hey guys,
Looking to see if anyone has any idea on how to grab a particular item from the Spotlight plist file. We are able to set the Spotlight settings via configuration profile, but now i need to use a script to check to see if the value is being managed or not. Since they seem to be in a dict, this is the part i am having trouble with. if i check defaults read /Users/$loggeduser/Library/Preferences/com.apple.Spotlight, it spits out everything. I would like to grab only the values we are looking for, { enabled = 0; name = "MENU_WEBSEARCH"; }

{ enabled = 0; name = "MENU_SPOTLIGHT_SUGGESTIONS"; },
Here is what i have so far:

#!/bin/sh
loggeduser=`ls -l /dev/console | cut -d " " -f4`
SPOT=defaults read /Users/$loggeduser/Library/Preferences/com.apple.Spotlight | "grab X"

if [ $SPOT == "0" ] 
then
:
else 
jamf policy -trigger spotlight_config
fi


Thanks for looking.
1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

Hmm. You should be able to pull what you need from system_profiler SPManagedClientDataType, though I don't usually like to invoke system_profiler as its a bit slow (though not very slow with that DatType)

You could try this, which should get you just the 1 or 0 that you're looking for.

defaults read /Users/$loggeduser/Library/Preferences/com.apple.Spotlight orderedItems | grep -B1 "MENU_WEBSEARCH" | awk '/enabled/{print $NF}' | sed 's/;$//'

Just do the same thing with the other item you need to look for.

There's also PlistBuddy, which can drill down into specific array elements a little easier than with defaults. Unfortunately how that array is structured I don't know if PlistBuddy would be much help.

If you really wanted to get fancy, you could have your script loop over all local accounts and look at each one's plist, then report them back in an array as the final result.

View solution in original post

5 REPLIES 5

davidacland
Honored Contributor II
Honored Contributor II

Bit of a different approach but could you use system_profiler SPManagedClientDataType | grep -c "com.apple.Spotlight" instead?

jrserapio
Contributor

@davidacland Thanks for the suggestion.
I tried this and got "0" as an output, even though the items in question were changed.

system_profiler SPManagedClientDataType | grep -c "com.apple.Spotlight"
0

Im trying to get my python on, and hopefully i can change the output to a list, then do a slice of that.

mm2270
Legendary Contributor III

Hmm. You should be able to pull what you need from system_profiler SPManagedClientDataType, though I don't usually like to invoke system_profiler as its a bit slow (though not very slow with that DatType)

You could try this, which should get you just the 1 or 0 that you're looking for.

defaults read /Users/$loggeduser/Library/Preferences/com.apple.Spotlight orderedItems | grep -B1 "MENU_WEBSEARCH" | awk '/enabled/{print $NF}' | sed 's/;$//'

Just do the same thing with the other item you need to look for.

There's also PlistBuddy, which can drill down into specific array elements a little easier than with defaults. Unfortunately how that array is structured I don't know if PlistBuddy would be much help.

If you really wanted to get fancy, you could have your script loop over all local accounts and look at each one's plist, then report them back in an array as the final result.

jrserapio
Contributor

@mm2270 Thanks for that. I will give it a go in the morning.

jrserapio
Contributor

@mm2270 Looks like that worked. Thanks!