Posted on 07-22-2015 02:51 PM
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.
Solved! Go to Solution.
Posted on 07-22-2015 04:27 PM
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.
Posted on 07-22-2015 03:22 PM
Bit of a different approach but could you use system_profiler SPManagedClientDataType | grep -c "com.apple.Spotlight"
instead?
Posted on 07-22-2015 04:01 PM
@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.
Posted on 07-22-2015 04:27 PM
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.
Posted on 07-22-2015 06:01 PM
@mm2270 Thanks for that. I will give it a go in the morning.
Posted on 08-04-2015 04:16 PM
@mm2270 Looks like that worked. Thanks!