Last active

Rename 2x images to "@2x" and move them to a parallel folder structure of 1x images

  • Download Gist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
set doubleDirPath_ to "path to 2x images"
set singleDirPath_ to "path to 1x images" -- also destination path
set ext_ to ".png"
set extLen_ to length of ext_
set suffix_ to "@2x"
tell application "Finder"
set doubleDir_ to folder doubleDirPath_
set singleDir_ to folder singleDirPath_
set dirs_ to (get every item of doubleDir_)
repeat with dir_ in dirs_
set dirName_ to (get name of dir_ as string)
set destDir_ to (get folder (singleDirPath_ & ":" & dirName_ as string))
set imgs_ to (get every item of dir_ whose name of it ends with ext_)
repeat with img_ in imgs_
set oldName_ to name of img_
set oldLen_ to length of oldName_
set oldName_ to (characters 1 thru (oldLen_ - extLen_) of oldName_ as string)
set newName_ to ""
if oldName_ does not end with suffix_ then
set newName_ to (oldName_ & suffix_ & ext_)
set name of img_ to newName_
end if
delete file (get name of img_ as string) of destDir_
duplicate img_ to destDir_
end repeat
end repeat
end tell

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.