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

Mac批量重命名动画帧:每4个分组映射为分层命名(工具/终端方案)

方案1:使用Transnomino批量重命名
  • 打开Transnomino,导入所有待重命名的PNG文件(确保文件按原文件名排序,Transnomino默认排序逻辑符合需求)
  • 点击「添加规则」,选择「自定义JavaScript」规则,输入以下脚本:
function rename(file) {
  const numStr = file.name.replace('.png', '');
  const num = parseInt(numStr, 10);
  
  const groupNum = Math.ceil(num / 4);
  const groupIndex = (num - 1) % 4;
  const prefix = ['a', 'b', 'c', 'd'][groupIndex];
  
  const formattedGroupNum = groupNum.toString().padStart(4, '0');
  return `${prefix}${formattedGroupNum}.png`;
}
  • 预览重命名结果,确认无误后点击「重命名」完成操作
方案2:使用Automator的AppleScript动作
  • 打开Automator,新建「文件夹动作」
  • 在顶部「文件夹动作接收自」下拉菜单中,选择存放待重命名文件的目标文件夹
  • 从左侧动作库拖拽「运行AppleScript」动作到右侧工作流区域
  • 替换默认脚本为以下代码:
on run {input, parameters}
    set prefixList to {"a", "b", "c", "d"}
    set sortedFiles to sort input by name
    
    repeat with i from 1 to count of sortedFiles
        set currentFile to item i of sortedFiles
        set fileName to name of currentFile as string
        set numStr to text 1 thru -5 of fileName
        set num to numStr as integer
        
        set groupNum to ((num + 3) div 4)
        set groupIndex to ((num - 1) mod 4) + 1
        set prefix to item groupIndex of prefixList
        
        set formattedGroupNum to text -4 thru -1 of ("0000" & groupNum as string)
        set newName to prefix & formattedGroupNum & ".png"
        
        tell application "Finder"
            set name of currentFile to newName
        end tell
    end repeat
    return input
end run

on sort(lst, by)
    if by is name then
        set lst to lst as list
        set astid to AppleScript's text item delimiters
        set AppleScript's text item delimiters to ASCII character 10
        set lst to do shell script "echo " & quoted form of (lst as string) & " | sort"
        set AppleScript's text item delimiters to astid
        return paragraphs of lst as alias list
    end if
end sort
  • 保存文件夹动作,将待重命名的PNG文件放入指定文件夹,Automator会自动执行重命名操作

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 23:57:19