vendredi 27 mars 2015

applescript strange behaviour with rename file script

I wrote this simple script that changes filenames of the folder Images on my desktop. The script works on the first run, however when I rerun it with a different string for the variable newName (same string would throw error: filename already exists). It only changes the name of the even numbers of "item x of the Folder". Can someone enlighten me on how this happens and what to do to avoid this peculiar behaviour. I'm having a hard time figuring this out. Thank you very much in advance.



tell application "Finder"
set theFolder to ((path to desktop folder) & "Images") as string as alias
set myImages to the name of every file of theFolder
set indexOfFolder to (count items in myImages) as number
set newName to "whateverName" as string

repeat with x from 1 to indexOfFolder
set name of item x of theFolder to newName & x & ".JPG"
end repeat
end tell


edit: After some more testing, it appears that the problem would not point exclusively to unchanged uneven numbers. With more then 20 files it appears to switch from 20 on to the even numbers that will not be renamed.


Aucun commentaire:

Enregistrer un commentaire