【问题标题】:Applescript move each file to its new folderApplescript 将每个文件移动到其新文件夹
【发布时间】:2013-05-12 18:50:07
【问题描述】:

我有 200 多张照片。我希望applescript:

  1. 根据文件名为这 200 张图片中的每张创建新文件夹
  2. 将文件移入其中

所以,即。 XXX.jpg 进入 XXX 文件夹。

任务或多或少很简单,但我在 mac 论坛上找到的所有 aplescript 代码都已过时。 我正在使用最新版本的山狮

【问题讨论】:

    标签: automation applescript osx-mountain-lion


    【解决方案1】:

    试试:

    set myFolder to (choose folder)
    tell application "Finder" to set myFiles to files of myFolder as alias list
    
    repeat with aFile in myFiles
        set bName to my baseName(aFile)
        tell application "Finder"
            set folderExists to exists folder bName of myFolder
            if not folderExists then make new folder at myFolder with properties {name:bName}
            move aFile to folder bName of myFolder
        end tell
    end repeat
    
    on baseName(myFile)
        tell application "System Events" to set {fileName, fileExt} to {name, name extension} of myFile
        return text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
    end baseName
    

    编辑

    set myFolder to findFolder()
    
    tell application "Finder" to set myFiles to files of myFolder as alias list
    
    repeat with aFile in myFiles
        set bName to my baseName(aFile)
        tell application "Finder"
            set folderExists to exists folder bName of myFolder
            if not folderExists then make new folder at myFolder with properties {name:bName}
            move aFile to folder bName of myFolder
        end tell
    end repeat
    
    ---------------- HANDLERS ----------------
    on baseName(myFile)
        tell application "System Events" to set {fileName, fileExt} to {name, name extension} of myFile
        return text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
    end baseName
    
    
    on findFolder()
        activate application "SystemUIServer"
        -- Bug pointed out by Lauri Ranta http://www.openradar.me/9406282
        tell application "Finder"
            activate
            set mySelection to (get selection)
            if mySelection ≠ {} then
                set mySelection to first item of (get selection)
                if mySelection's class = folder then
                    set currentFolder to mySelection
                else if mySelection's class = document file then
                    set currentFolder to parent of mySelection
                else if mySelection's class = alias file then
                    set currentFolder to original item of mySelection
                end if
            else
                set currentFolder to target of front Finder window
            end if
        end tell
        return (currentFolder as alias)
    end findFolder
    

    【讨论】:

    • 谢谢。可以以“我的文件夹”是查找器显示的方式对其进行中间处理吗?也就是我在 nfinder 中打开文件夹,这就是工作应该去的文件夹。那么会更通用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    相关资源
    最近更新 更多