Automator 中创建一个 快速操作(Quick Action),加入finder右键中快速使用

步骤 1:打开 Automator 并创建“快速操作”

  1. 打开 Automator(应用程序 > Automator)。
  2. 选择 “快速操作”(Quick Action),然后点击 “选择”。
  3. 在右上角设置:
    . “工作流程接收当前” → “文件或文件夹”(在 Finder 中选中)。
    . “位于” → “Finder.app”(确保在 Finder 中可用)。

步骤 2:添加“运行 Shell 脚本”操作

  1. 在左侧搜索栏输入 “运行 Shell 脚本”,然后拖拽到右侧工作区。
  2. 在 “Shell” 下拉菜单中选择 /bin/bash(或 /bin/zsh,取决于你的系统)。
  3. 在脚本区域粘贴以下代码:
#!/bin/bash
#递归修改指定目录及其内容的权限,确保:
#所有子目录 的权限设为 755(rwxr-xr-x,允许所有者读写执行,其他用户只读和执行)。
#所有普通文件 的权限设为 644(rw-r--r--,允许所有者读写,其他用户只读)。
#如果输入的不是目录,则报错提示。
for f in "$@"; do
    if [ -d "$f" ]; then
        echo "正在修改目录权限: $f"
        find "$f" -type d -exec chmod 755 {} \;
        echo "正在修改文件权限: $f"
        find "$f" -type f -exec chmod 644 {} \;
    else
        echo "错误: 不是目录 - $f"
    fi
done
# 用vscode打开文件或者文件夹
for f in "$@"
do
    open -a "Visual Studio Code" "$f"
done

步骤 3:保存快速操作

  1. 点击 “文件” > “保存”。
  2. 输入名称(如 “递归修改权限 755”)。
  3. 点击 “保存”。
  4. 保存位置:~/Library/Services/
posted @ 2025-11-20 14:55  nate_pan  阅读(26)  评论(0)    收藏  举报