如何在AppleScript中将Finder更改为父目录?

时间:2019-04-02 23:39:47

标签: applescript

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

3 个答案:

答案 0 :(得分:1)

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

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

实际上,“。jpeg”中的“ e”真的值得死

答案 1 :(得分:0)

这应该让您入门

tell application "Finder" to get (container of (path to me)) as text

我的路径可以是任何HFS路径(例如您文件之一的路径)

答案 2 :(得分:0)

此AppleScript代码适用于使用最新版本的macOS Mojave的我。

以下代码可以满足您的所有需求。

property setNameExtension : "jpg" -- Change To Whatever You Want

tell application "Finder"
    set selectedFiles to selection as alias list -- Currently Selected Files In Finder
    set containerOfContainerOf to container of (container of item 1 of selectedFiles)
    repeat with i in selectedFiles
        set renamedItems to move i to containerOfContainerOf
        set the name extension of renamedItems to setNameExtension
    end repeat
end tell