2012-08-15 36 views
0

此脚本与上一个问题中提到的相同,即将@ 2x添加到文件夹中的所有文件,但如何制作或更改此Apple脚本以删除@ 2x。如何使用Apple脚本从图像中删除@ 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 

回答

1
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 

它会更容易做到这一点在shell:IFS=$'\n'; for f in $(find ~/Desktop -name '*@2x*'); do mv "$f" "${f//@2x/}"; done

+0

真棒,这就是诀窍。我不是脚本或终端大师,所以再次感谢! – SlickRemix 2012-08-15 23:35:22