我编写了一个脚本来将用户的公司网络共享添加到他们在 Mac OS X 中的“连接到服务器”列表中(Finder --> Go --> Connect to Server...)。此脚本直接写入 com.apple.sidebarlists.plist 的备份,然后在使用 mv 验证后替换它。我无法让 Finder 认识到已对此 plist 进行了更改。重新启动系统会很好地显示列表中的新服务器。但是注销/登录和重新启动(杀死)Finder 不会。我也试过 killall SystemUIServer 和 killall cfprefsd ( http://blog.design79.co.uk/?p=1761 ) 没有运气。
有没有人遇到过这种情况,是否有解决方案可以在不重新启动的情况下更新列表?
谢谢!
这是我的脚本的一部分,它执行写入/移动/等以供参考。
# ...
cp "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: The users com.apple.sidebarlists.plist could not be backed up. Aborting...."
exitfunction
else
echo "$(date): com.apple.sidebarlists.plist was backed up."
fi
defaults delete "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist" favoriteservers
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not remove favoriteservers from com.apple.sidebarlists.mod.plist. Aborting...."
exitfunction
else
echo "$(date): Favoriteservers was removed from com.apple.sidebarlists.plist."
fi
defaults write "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist" favoriteservers -dict Controller CustomListItems CustomListItems REPLACEME
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not add favoriteservers to com.apple.sidebarlists.mod.plist. Aborting...."
exitfunction
else
echo "$(date): Favoriteservers was re-added to com.apple.sidebarlists.plist with placeholder."
fi
plutil -convert xml1 "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not convert com.apple.sidebarlists.mod.plist to XML1 format. Aborting...."
exitfunction
else
echo "$(date): com.apple.sidebarlists.mod.plist was successfully converted to XML1."
fi
sed -i "" "/ *<string>REPLACEME<\/string>/r $tempfile5" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not inject new server list. Aborting...."
exitfunction
else
echo "$(date): New server list was injected into com.apple.sidebarlists.mod.plist."
fi
sed -i "" 's/ *<string>REPLACEME<\/string>//g' "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not remove placeholder tag in com.apple.sidebarlists.mod.plist. Aborting...."
exitfunction
else
echo "$(date): Placeholder tag was removed from com.apple.sidebarlists.mod.plist."
fi
plutil -convert binary1 "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not convert com.apple.sidebarlists.mod.plist into binary format. Aborting...."
exitfunction
else
echo "$(date):com.apple.sidebarlists.mod.plist was successfully converted into binary1."
fi
plutil -lint "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: Could not validate com.apple.sidebarlists.mod.plist. Aborting...."
exitfunction
else
echo "$(date):com.apple.sidebarlists.mod.plist was successfully verified as a valid XML file."
fi
mv "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist.old"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: com.apple.sidebarlists.plist could not be moved. Aborting...."
exitfunction
else
echo "$(date):com.apple.sidebarlists.mod.plist was successfully renamed to com.apple.sidebarlists.plist.old."
fi
mv "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.mod.plist" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist"
if [[ "$?" != 0 ]]; then
echo "$(date):ERROR: apple.sidebar.mod.plist could not be moved. Aborting...."
mv "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist.old" "$enduserhomefolder/Library/Preferences/com.apple.sidebarlists.plist"
echo "$(date):ERROR: com.apple.sidebarlists.plist plist restored from backup"
exitfunction
else
echo "$(date):com.apple.sidebarlists.mod.plist was successfully renamed to com.apple.sidebarlists.plist.old."
fi
# ....