script to change visibility of idisk in finder sidebar?

Walter
New Contributor II

Hi all,

Is there a way to hide idisk in the finder sidebar via script? Our secure configuration guidelines recommend this being hidden. There is a plist file /Users//<user>/Library/Preferences/com.apple.sidebarlists.plist where you can see the various items that appear in the sidebar and their visibility = NeverVisible. I can't figure out how to set that for iDisk if it isn't already set.

That plist was a binary file. I converted it to an xml format using plutil -convert xml1 <file> so that I could see what is in there. I suppose I could 1) convert from binary to xm1, 2) use a sed command to add the line, and 3) convert it back to binary?

Walter
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

12 REPLIES 12

nessts
Valued Contributor II

a defaults write with the proper amount of <> things would do the trick but it would be a pain in the rear to figure out, PlistBuddy might be able to do it, but I can only get it to print with
/usr/libexec/PlistBuddy -c Print ~/Library/Preferences/com.apple.sidebarlists.plist
I have not figured out how to print the one item, so yeah if it were me I would write a perl script to convert to xml.
then read through the file until I found iDisk
then find the Visibility line and change it to NeverVisible, but you probably have to do this every single time the user logs in because they could change it by opening finder preferences and checking the box.
then convert the file back, but there has to be a more appley way of doing it.

--
Todd Ness
Technology Consultant/Non-Windows Services
Americas Regional Delivery Engineering
HP Enterprise Services

Walter
New Contributor II

figured it out

convert plist to xm1

use this awk to add the visibility key cat <sidebar plist> | awk '!/iDisk/ { print; } /iDisk/ { print; print "<key>Visibility</key> <string>NeverVisible</string>"; }' > <new sidebar plist>

convert plist to binary
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

talkingmoose
Moderator
Moderator

convert plist to binary
On 7/7/11 3:05 PM, "Rowe, Walter" <walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>> wrote:

No need to convert back to binary. The application will read XML just fine. If it has to write back to the file then it automatically converts it back to binary.

--

William Smith
Technical Analyst
Merrill Communications LLC
(651) 632-1492

Walter
New Contributor II

Got it working.
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

#!/bin/bash

# get the list of sidebar pList files
sidebars=$(echo /Users/*/Library/Preferences/com.apple.sidebarlists.plist)

# cycle through the sidebar plist files
for pList in $sidebars; do

# get the domain of the plist file domain=$(dirname $pList)/$(basename $pList .plist)

# extract the current visibility setting # possible values are empty string, NeverVisible, AlwaysVisible visibility=$(defaults read ${domain} systemitems | grep -A 2 "iDisk" | grep "Visibility" | awk '{ print $NF }')

# if already set to NeverVisible, skip if [ "${visibility}" = "NeverVisible;" ]; then continue fi

# create temp file names pListOld=${pList}.casper-$(date +%Y-%m-%d-%T) pListNew=${pList}.new

# convert plist from binary to xml plutil -convert xml1 $pList

# if empty string, visibility isn't set so set it # add key/value pair Visibility/NeverVisible after iDisk line in xml file if [ -z "${visibility}" ]; then cat ${pList} | awk '!/iDisk/ { print; } /iDisk/ { print; print "<key>Visibility</key> <string>NeverVisible</string>"; }' > ${pListNew} fi

# if visibility set to AlwaysVisible, change to NeverVisible if [ "${visibility}" = "AlwaysVisible;" ]; then cat ${pList} | sed '/iDisk/,/AlwaysVisible/s/AlwaysVisible/NeverVisible/' > ${pListNew} fi

# save original plist, copy new plist into place cp ${pList} ${pListOld} cp ${pListNew} ${pList}

# convert plist from xml to binary plutil -convert binary1 ${pList}
done

Walter
New Contributor II

Made a minor change to insure the user retains ownership of the backup file. Also provided some comments at the top about expectations for taking effect.
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

#!/bin/bash
#
# control-051-hide-idisk.sh
#
# date: 2011-07-08
# author: walter rowe
# org: nist, us dept of commerce
#
# if iDisk is visible in the Finder sidebar, set it to hidden.
#
# this only takes effect after the user logs out and back in.
# any change the user makes to Finder preferences between when
# this is run and when they log out will overwrite this change.
# best to run this periodically so it eventually takes effect.

# get the list of sidebar pList files
finderSidebars=$(echo /Users/*/Library/Preferences/com.apple.sidebarlists.plist)

# cycle through the sidebar plist files
for pList in $finderSidebars; do

# get the domain of the plist file domain=$(dirname $pList)/$(basename $pList .plist)

# extract the current visibility setting # possible values are empty string, NeverVisible, AlwaysVisible visibility=$(defaults read ${domain} systemitems | grep -A 2 "iDisk" | grep "Visibility" | awk '{ print $NF }')

# if already set to NeverVisible, skip if [ "${visibility}" = "NeverVisible;" ]; then continue fi

# create temp file names pListOrig=${pList}.casper-$(date +%Y-%m-%d-%T)

# convert plist from binary to xml plutil -convert xml1 $pList

# save the original plist (use -p to preserve date/time/owner/etc) cp -fp ${pList} ${pListOrig}

# if empty string, visibility isn't set so set it # add key/value pair Visibility/NeverVisible after iDisk line in xml file if [ -z "${visibility}" ]; then cat ${pListOrig} | awk '!/iDisk/ { print; } /iDisk/ { print; print "<key>Visibility</key> <string>NeverVisible</string>"; }' > ${pList} fi

# if visibility set to AlwaysVisible, change to NeverVisible if [ "${visibility}" = "AlwaysVisible;" ]; then cat ${pListOrig} | sed '/iDisk/,/AlwaysVisible/s/AlwaysVisible/NeverVisible/' > ${pList} fi

# convert plist from xml to binary plutil -convert binary1 ${pList}
done

rmanly
Contributor III

Incidentally here is the PlistBuddy way...makes everything a bit easier ;)

$ /usr/libexec/PlistBuddy Library/Preferences/com.apple.sidebarlists.plist
-c "Set systemitems:VolumesList:2:Visibility NeverVisible"

Ryan M. Manly
Glenbrook High Schools

Walter
New Contributor II

Thanks!
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

nessts
Valued Contributor II

I knew there would be somebody with the gumption to figure out how to do it the right way. Nice job.

--
Todd Ness
Technology Consultant/Non-Windows Services
Americas Regional Delivery Engineering
HP Enterprise Services

rmanly
Contributor III

Incidentally you want to make sure you are just not iterating over a string
and actually use an array.

I tried this out and it worked as expected. The only problem will be when
Apple decides to make iDisk the a different number in the array :(

#!/bin/bash

plists=(/Users/*/Library/Preferences/com.apple.sidebarlists.plist)

for file in "${plists[@]}"; do /usr/libexec/PlistBuddy "${file}" -c "Set
systemitems:VolumesList:2:Visibility NeverVisible"
done

Ryan M. Manly
Glenbrook High Schools

http://mywiki.wooledge.org/BashGuide/Arrays

Walter
New Contributor II

Thanks Ryan.

My script does iterate through all the users who have a sidebar plist. It also has NO dependence on where Apple places iDisk in the array.

If the visibility key is not there, it adds it. If it is there, it makes sure it is set to NeverVisible.

Your script is short and sweet. Mine can't be fouled up by Apple.

Walter
--
Walter Rowe, System Hosting
Enterprise Systems / OISM
walter.rowe at nist.gov<mailto:walter.rowe at nist.gov>
301-975-2885

#!/bin/bash
#
# control-051-hide-idisk.sh
#
# date: 2011-07-08
# author: walter rowe
# org: nist, us dept of commerce
#
# if iDisk is visible in the Finder sidebar, set it to hidden.
#
# this only takes effect after the user logs out and back in.
# any change the user makes to Finder preferences between when
# this is run and when they log out will overwrite this change.
# best to run this periodically so it eventually takes effect.

# get the list of sidebar pList files
finderSidebars=$(echo /Users/*/Library/Preferences/com.apple.sidebarlists.plist)

# cycle through the sidebar plist files
for pList in $finderSidebars; do

# get the domain of the plist file domain=$(dirname $pList)/$(basename $pList .plist)

# extract the current visibility setting # possible values are empty string, NeverVisible, AlwaysVisible visibility=$(defaults read ${domain} systemitems | grep -A 2 "iDisk" | grep "Visibility" | awk '{ print $NF }')

# if already set to NeverVisible, skip if [ "${visibility}" = "NeverVisible;" ]; then continue fi

# create temp file names pListOrig=${pList}.casper-$(date +%Y-%m-%d-%T)

# convert plist from binary to xml plutil -convert xml1 $pList

# save the original plist (use -p to preserve date/time/owner/etc) cp -fp ${pList} ${pListOrig}

# if empty string, visibility isn't set so set it # add key/value pair Visibility/NeverVisible after iDisk line in xml file if [ -z "${visibility}" ]; then cat ${pListOrig} | awk '!/iDisk/ { print; } /iDisk/ { print; print "<key>Visibility</key> <string>NeverVisible</string>"; }' > ${pList} fi

# if visibility set to AlwaysVisible, change to NeverVisible if [ "${visibility}" = "AlwaysVisible;" ]; then cat ${pListOrig} | sed '/iDisk/,/AlwaysVisible/s/AlwaysVisible/NeverVisible/' > ${pList} fi

# convert plist from xml to binary plutil -convert binary1 ${pList}
done

MrP
Contributor III

It appears Yosemite no longer uses this file in the same way, if at all. Has anyone gotten this to work on 10.10?

MrP
Contributor III

Nevermind. Found this: https://jamfnation.jamfsoftware.com/discussion.html?id=13639