Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Rename 2x images to "@2x" and move them to a parallel folder structure of 1x images
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment