Applescript 删除部分文件名

Applescript 删除部分文件名,applescript,rename,Applescript,Rename,我想把难看的文件名(作为我糟糕编程的副产品)如“小册子xxx.pdf kopie.pdf”改为“xxx.pdf”。Automator将其更改为>“xxx.pdf”(文件名前面有一个非常讨厌的空格 这就是我能想到的 tell application "Finder" set allFiles to selection search of (name of every item of allFiles) for "Booklet " try if file exist

我想把难看的文件名(作为我糟糕编程的副产品)如“小册子xxx.pdf kopie.pdf”改为“xxx.pdf”。Automator将其更改为>“xxx.pdf”(文件名前面有一个非常讨厌的空格

这就是我能想到的

    tell application "Finder"
    set allFiles to selection
    search of (name of every item of allFiles) for "Booklet "
try
    if file exists then delete "Booklet " of name
end try
    search of (name of every item of allFiles) for ".pdf kopie"
try
    if file exists then delete ".pdf kopie" of name
end try
    end tell

非常感谢!

您可以通过设置
name
属性来重命名文件:

activate application "SystemUIServer" -- http://www.openradar.me/9406282
tell application "Finder"
    activate
    repeat with f in (get selection)
        if name of f ends with "kopie.pdf" then
            set name of f to text 9 thru -11 of (get name of f)
        end if
    end repeat
end tell
或者在shell中运行类似的操作:

cd directory; for f in *kopie.pdf; do f2=${f% *}; mv "$f" "${f2##* }"; done

${f%*}
删除最短的
​ *f
${f2###*}
结尾的code>模式删除最长的
*​模式从
f2开始

谢谢你帮助这个noob!它起作用了:-)在理解文本9到11的含义时遇到了一些困难,但现在我明白了(字符)。。。