【问题标题】:AppleScript: Create new folder from file name and move file into that folderAppleScript:从文件名创建新文件夹并将文件移动到该文件夹​​中
【发布时间】:2012-06-27 06:11:28
【问题描述】:

基本上,我正在尝试在 Automator 中创建文件夹操作,因此每当将文件添加到特定文件夹时,它都会创建一个与文件名匹配的子文件夹(不带扩展名),然后将文件移动到该子文件夹中。

到目前为止,我已经成功地使用了来自该站点 (Create new folder named with a specified file name in Automator) 的帖子来创建将创建新文件夹的脚本。但是,我无法修改脚本以将原始文件移动到新文件夹中。

任何帮助将不胜感激。这是我正在使用的完整脚本以供参考:

    on run {input, parameters} -- make new folders from base file names

    set output to {}

    repeat with anItem in the input -- step through each item in the input

        set anItem to anItem as text
        tell application "System Events" to tell disk item anItem
            set theContainer to path of container
            set {theName, theExtension} to {name, name extension}
        end tell
        if theExtension is in {missing value, ""} then
            set theExtension to ""
        else
            set theExtension to "." & theExtension
        end if
        set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part

        tell application "Finder"
            make new folder at folder theContainer with properties {name:theName}
            set end of output to result as alias
        end tell
    end repeat

    return input -- or output
end run

提前致谢!

【问题讨论】:

    标签: macos applescript automator


    【解决方案1】:

    将此文件夹操作添加到您的目标文件夹:

    on adding folder items to theFolder after receiving theFiles
        repeat with aFile in theFiles
            tell application "System Events" to set {Nm, Ex, pPath} to aFile's {name, name extension, POSIX path of container}
            set BN to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
            set thePath to (pPath & "/" & BN & "/" as text)
            do shell script "mkdir -p " & quoted form of thePath
            delay 0.5
            tell application "Finder" to move aFile to POSIX file thePath
        end repeat
    end adding folder items to
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      • 2014-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多