Skip to main content
Solved

Parsing options in com.apple.Spotlight


Forum|alt.badge.img+7

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.

Best answer by mm2270

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 original
Did this topic help you find an answer to your question?

5 replies

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • July 22, 2015

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


Forum|alt.badge.img+7

@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
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • Answer
  • July 22, 2015

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.


Forum|alt.badge.img+7

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


Forum|alt.badge.img+7

@mm2270 Looks like that worked. Thanks!


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings