defaults write 权限修复$ cd ~/Library/Containers/com.apple.mail $ ls ls: cannot open directory '.': Op

本文介绍了解决Mojave系统中Mail应用被默认阻止的问题,通过将Bash等应用添加到全盘访问列表,可以解锁对~/Library/Containers/com.apple.mail目录的访问限制,并展示如何查看Mail应用的全部设置。

This may be caused by permissions. On Mojave Mail is blocked from apps by default. In Bash you will see this by default:

$ cd ~/Library/Containers/com.apple.mail

$ ls

ls: cannot open directory '.': Operation not permitted
And defaults read -app Mail will only show these options:
{
BundleCompatibilityVersion = 3;
EnableBundles = 1;
NSNavLastRootDirectory = "...";
NSNavPanelExpandedSizeForOpenMode = "{720, 448}";
}

You need to add Bash (and maybe others like iTerm, Terminal, etc) to the Full Disk Access list. When you click +, use ⇧+ ⌘ + G 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 Mailand it will show all settings. It does not work for me in tmux (not sure why yet). Run this command in a bare shell.

$ defaults read -app Mail | fgrep DisableSendAnimations

DisableSendAnimations = 1;

 

在使用 `sudo` 执行 Python 脚本时遇到“命令未找到”错误,通常是由于 `sudo` 环境下无法找到 Python 可执行文件或相关模块。以下是几种可能的原因及解决方法: ### 3.1 检查 Python 是否已正确安装 首先确保系统中已经安装了 Python,并且可以通过终端直接调用。使用以下命令验证安装情况: ```bash which python which python3 ``` 如果系统返回类似 `/usr/bin/python` 或 `/usr/bin/python3` 的路径,说明 Python 已安装。如果未找到路径,需安装 Python: ```bash sudo apt update sudo apt install python3 ``` ### 3.2 检查 `PATH` 环境变量 `sudo` 执行命令时会使用不同的环境变量,可能导致无法找到 Python 可执行文件。可以通过以下命令查看当前环境中的 `PATH`: ```bash echo $PATH sudo echo $PATH ``` 如果发现 `sudo` 下的 `PATH` 缺少 `/usr/bin` 或 `/usr/local/bin`,可以通过编辑 `sudoers` 文件来修复: ```bash sudo visudo ``` 找到以下行并注释掉(避免重置环境变量): ``` Defaults env_reset ``` 或者添加以下行以保留当前用户的 `PATH`: ``` Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" ``` 保存并退出后,重新尝试执行脚本。 ### 3.3 使用完整路径执行 Python 脚本 为了避免环境变量带来的问题,可以使用 Python 的完整路径来执行脚本。例如: ```bash sudo /usr/bin/python3 your_script.py ``` 这样可以确保 `sudo` 直接调用系统中已知的 Python 解释器。 ### 3.4 添加用户态模块路径到 `sudo` 的 Python 环境 如果脚本依赖某些用户安装的 Python 模块(如通过 `pip install --user` 安装的模块),`sudo` 环境下可能无法找到这些模块。可以通过创建 `.pth` 文件将用户路径添加到 `sudo` 的 Python 搜索路径中[^3]: ```bash sudo nano /usr/lib/python3/dist-packages/my.pth ``` 在文件中添加用户模块路径,例如: ``` /home/username/.local/lib/python3.8/site-packages ``` 保存并退出后,再次尝试执行脚本。 ### 3.5 配置 PyCharm 的 Python 解释器 如果问题发生在 PyCharm 中,应配置正确的 Python 解释器路径,而不是使用 `sudo` 启动整个 IDE。可以通过以下步骤设置: 1. 打开 PyCharm,进入 **File > Settings > Project: <project_name> > Python Interpreter**。 2. 点击齿轮图标,选择 **Add...**。 3. 选择 **System Interpreter**,并浏览至 Python 的安装路径(可通过 `which python3` 查看)。 4. 确认后保存设置,重新运行脚本。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值