0

该脚本的工作原理与上一个问题中提到的一样,可将@2x 添加到文件夹中的所有文件,但是我如何制作或更改此苹果脚本以删除@2x。

set appendable to "@2x"
set theFolder to choose folder
tell application "Finder"
    set theFiles to (files of entire contents of theFolder) as alias list
    repeat with theFile in theFiles
        set FileExtension to theFile's name extension as string
        set FileName to theFile's name as string
        set FileBaseName to text 1 thru ((offset of "." in FileName) - 1) of FileName
        set theFile's name to FileBaseName & appendable & "." & FileExtension
    end repeat
end tell
4

1 回答 1

2
tell application "Finder"
    repeat with f in (files of entire contents of (choose folder) as alias list)
        set n to name of f
        set x to name extension of f
        if n does not end with "@2x." & x then next
        set name of f to text 1 thru (-5 - (count x)) of n & "." & x
    end repeat
end tell

It would be easier to do it in a shell: IFS=$'\n'; for f in $(find ~/Desktop -name '*@2x*'); do mv "$f" "${f//@2x/}"; done.

于 2012-08-15T22:01:19.490 回答