Is it possible to manage preferences for sandboxed/containerized apps?

bpavlov
Honored Contributor

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?

5 REPLIES 5

stevewood
Honored Contributor II
Honored Contributor II

@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:

Remote Destkop 8 Connections

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

bpavlov
Honored Contributor

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.

Widner
New Contributor

On a side note, does anyone know of a way to restrict passwords from being saved in connections?

timsutton
Contributor

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.

davidacland
Honored Contributor II

@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 :)