Posted on 05-04-2015 07:37 AM
As the subject states, is it possible to manage preferences for sandboxed/containerized apps? For example, Microsoft Remote Desktop from the App Store now stores its preferences in ~/Library/Containers/com.microsoft.rdc.mac/Data/Library/Preferences/com.microsoft.rdc.mac.plist
because its a sandboxed app. Short of manually modifying the plist file, any other options?
Posted on 05-04-2015 07:42 AM
@bpavlov with RDC in particular, what are you trying to manage? If you are trying to create connections, yes, you can do that. @bentoms has a write up on his web site about it:
I personally use a modified method:
#!/bin/sh
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`
# global
RDCPLIST=/Users/$loggedInUser/Library/Containers/com.microsoft.rdc.mac/Data/Library/Preferences/com.microsoft.rdc.mac.plist
myUUID=`uuidgen`
LOGPATH='<yourlogpath>'
# set variables
connectionName="<nameoftheconnection"
hostAddress="<addressfortheconnection>"
# if you need to put an AD domain, add it to userName below
userName=''
# AD domain plus logged in user
userName+=$loggedInUser
resolution="1280 1024"
colorDepth="32"
fullScreen="FALSE"
scaleWindow="FALSE"
useAllMonitors="TRUE"
set -xv; exec 1> $LOGPATH/rdcPlist.txt 2>&1
defaults write $RDCPLIST bookmarkorder.ids -array-add "'{$myUUID}'"
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.label -string "$connectionName"
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.hostname -string $hostAddress
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.username -string $userName
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.resolution -string "@Size($resolution)"
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.depth -integer $colorDepth
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.fullscreen -bool $fullScreen
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.scaling -bool $scaleWindow
defaults write $RDCPLIST bookmarks.bookmark.{$myUUID}.useallmonitors -bool $useAllMonitors
chown -R "$loggedInUser:staff" /Users/$loggedInUser/Library/Containers/com.microsoft.rdc.mac
Posted on 05-04-2015 10:26 AM
It was more of a general question as to whether there was a BETTER way to do it. I happened to just use Microsoft Remote Desktop because it was a simple app that I was just dealing with at the time of my post. Actually I wasn't trying to create connections, but rather skip the first prompt window you get when opening it up.
It looks like there isn't a better way short of writing to the plist file using defaults. That works for me. Just wish Apple made profiles "containers"-aware. Oh well. Thanks for the post. Definitely interesting to read the script and see what others are doing.
Posted on 11-05-2015 11:51 AM
On a side note, does anyone know of a way to restrict passwords from being saved in connections?
Posted on 04-22-2016 11:20 AM
About manipulating preferences for a sandboxed app, in my experience you don't need to care that it's sandboxed for the purposes of getting/setting prefs. Simply defaults write com.microsoft.rdc.mac <key> <value>
sets the key (eventually) in the container plist, and the preferences subsystem knows whether the app is sandboxed or not.
Posted on 04-22-2016 11:30 AM
@Widner the two ways that may work would be to write the setting at login defaults write...
as @timsutton said, then a defaults delete...
at logout.
Alternatively, delivering the setting via a config profile, although that may affect other connections they have setup.
Just ideas though. Nothing tested or proven :)