首页 > 解决方案 > 如何将 Finder 更改为 AppleScript 中的父目录?

问题描述

我需要创建一个 Mac Automator 或 AppleScript 来执行以下操作:1)选择一堆文件 2)重命名所选文件的扩展名 3)将重命名的文件移动到父文件夹的父文件夹(2 级)我可以在 Automator 中执行 1&2,但我假设我需要 #3 的脚本。任何帮助,将不胜感激!

标签: applescript

解决方案


tell application "Finder"
    set OriginalSin to the insertion location
    set Man to a reference to the parent of OriginalSin
    set Lord to a reference to the parent of Man

    if not (the Lord exists) then return "Dawkins was right."

    set the Shadows to make new folder at OriginalSin ¬
        with properties {name:"___EVIL___"}

    move the selection to the Shadows

    set Worthy to a reference to every file in the Shadows
    set the name extension of the Worthy to "god"


    set Forsaken to the name in the Lord's files
    set Righteous to the Worthy where its name is not in the Forsaken

    move the Righteous to the Lord without replacing
    move the Worthy to OriginalSin
    delete the Shadows
end tell

我不会使用“上帝”作为扩展名,系统不会将其识别为已知文件类型。事实上,考虑一下为什么您希望手动更改文件扩展名,除了纯文本文件之外,我想不出有必要这样做的情况†</sup>。macOS 使用文件扩展名来帮助确定文件类型,并将它们链接到适当的应用程序,这些应用程序将不再能够作为您修改的文件的打开器。

†</sup>其实“.jpeg”中的“e”真的该死


推荐阅读