You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac下Shell脚本复制到Google Drive正常,cron/launchctl执行失败

Mac上cron/launchctl执行Google Drive复制脚本失败问题

设备环境:MacBook Pro(2 GHz四核Intel Core i5,16GB内存),运行Sonoma 14.5

问题场景

尝试设置夜间任务,通过Shell脚本编辑本地文件后,复制到Google桌面集成的本地Google Drive目录。脚本在终端执行正常,但添加到cron或通过launchctl执行时失败。

测试脚本(已替换<user>为实际用户名)

#!/bin/bash

echo "test data" > /Users/<user>/Scripts/Scratch/testfile.txt

cp /Users/<user>/Scripts/Scratch/testfile.txt /Users/<user>/Google*/My*/copied.txt

exit 0

尝试过的解决方法及报错

怀疑Google Drive目录的空格是问题根源,尝试以下方案均无效(终端执行正常,cron/launchctl执行失败):

  • 使用通配符*替代目录名中的空格
  • 手动转义空格:
    cp /Users/<user>/Scripts/Scratch/testfile.txt /Users/<user>/Google\ Drive/My\ Drive/copied.txt
    
  • 创建硬链接或符号链接规避空格路径

cron执行报错

  • 转义空格版本报错:
    cp: /Users/<user>/Google Drive/My Drive/copied.txt: Operation not permitted
    
  • 通配符版本报错:
    cp: /Users/<user>/Google*/My*/copied.txt: No such file or directory
    

已解决情况与剩余问题

  • 给cron授予全磁盘访问权限后,cron的执行问题已解决
  • 给launchd和launchctl授予相同的全磁盘访问权限后,launchd执行脚本仍失败

内容的提问来源于stack exchange,提问作者Orestes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 04:44:57