dotfiles: `defaults write` doesn't work on Safari on Mojave
Is anyone else noticing that using defaults write com.apple.safari something-or-other
doesn’t work on Mojave?
I noticed that they seem to have moved Safari’s preference plist so that it’s now buried under ~/Library/Containers
(sigh). So I tried replacing “com.apple.safari
” with “-app safari
”, hoping that this would point defaults
to the correct thing. (I found I had to do this with Preview a while back.)
But alas, it doesn’t work.
If it isn’t just me, I’ll report this to Apple. Seems like a bad bug.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 26
Commits related to this issue
- macOS: add comment for permissions error with defaults write Also add shellcheck to Brewfile. Refs: https://github.com/mathiasbynens/dotfiles/issues/849 — committed to gibfahn/dot by gibfahn 5 years ago
- Support containerized Safari See https://github.com/mathiasbynens/dotfiles/issues/849 — committed to MattiSG/DotFiles by MattiSG 4 years ago
- address full disk access issues that may be encountered during macos setup See https://github.com/mathiasbynens/dotfiles/issues/849 — committed to Okeanos/dotfiles by Okeanos a year ago
This may be caused by permissions. On Mojave Mail is blocked from apps by default. In Bash you will see this by default:
And
defaults read -app Mail
will only show these options:You need to add Bash (and maybe others like iTerm, Terminal, etc) to the Full Disk Access list. When you click +, use <kbd>⇧</kbd> + <kbd>⌘</kbd> + <kbd>G</kbd> to open the Go to folder dialog so you can pick items like Bash. You need to pick the exact one you are using. I am using MacPorts so everything is in
/opt/local/bin
for me.Once you’ve done this, start a new shell (already running shells will not work) and type
defaults read -app Mail
and it will show all settings. It does not work for me in tmux (not sure why yet). Run this command in a bare shell.For Safari you will have to change the command to use the property list file without the
.plist
extension withdefaults
:There are other property lists as well in this path.
I presume almost all apps including Apple’s are going in this direction, as this is what has been done on iOS especially since 11.
Apple always leaves hints regarding migrations:
using the Preferences app to enable Terminal, bash, etc somewhat defeats the automate-ability of a bootstrapping script to automate preferences. Is there a way to automate this part while maintaining SIP enabled?
Makes sure to give Terminal Full Access (I recommend you do this temporarily). Then commands like “defaults write com.apple.mail DisableInlineAttachmentViewing -boolean yes” may work
To work around this a bit more, is anyone aware of a scriptable way to put an application into the “Full Disk Access” list? I’ve seen other applications add themselves into Settings -> Security & Privacy -> Privacy -> Accessibility before. Of course they are by default unchecked, but the user gets prompted to unlock and enable them, which is better than nothing. Would love to find a way to script that before running my dotfiles.
Right, not all apps work with the
-app
invocation. (And it has always been thus, it’s not a Mojave regression.) If memory serves, only applications that are located in either/Applications
or~/Applications
—or at least are symlinked into one of those two—will work in this way. I’m unsure whether all apps that live or symlinkedly live there will work with-app
.I don’t know what to say about the brewed bash, but it might be relevant that what’s in
/usr/local/bin
is a symlink to bash and not bash itself. Perhaps using/usr/local/opt/bash/bin/bash
will work, because though elements of that path are symlinks, the endpoint isn’t.I used to use
-app
only when not using it would fail (i.e., containerized on pre-Mojave), but I think I’m now going to never use-app
(and where necessary use the full path through the container), at least for scripting. The point of scripting these is to run them on a fresh user (maybe even without being logged into the GUI), which conflicts with the rigamarole of manually granting Full Disk Access.It should be easy to create a wrapper script that will automatically prepend the container-y path for any domain that is antecedently known to live in a container.