MacOS – AppleScript to copy images that names are multiple of 30 to another folder

applescriptdeletingmacos

I have a folder with hundreds of pictures like this:
Montana_1.jpg, Montana_2.jpg, …, Montana_4500.jpg

I only want to use the pictures where the name is multiple of 30. I was wondering if an AppleScript would

  1. Open the folder containing the pictures.
  2. Copy only the pictures that are multiple of 30 like
    Montana_30.jpg, Montana_60.jpg, …, Montana_120.jpg.
  3. Move to another folder.

Another way could be to delete any picture that is not multiple of 30.

Best Answer

You can do this from the command line. The following will match all images which are a multiple of 30 and copy them to the destination folder.

/bin/zsh -c "cp /path/to/source/Montana_{30..4500..30}.jpg /path/to/destination/"
  • Replace /path/to/source with the path to the containing folder for the images.
  • Replace 4500 with the number of the last image in the folder.
  • Replace /path/to/destination with the path to the containing folder where the images which are a multiple of 30 will be copied to.

To move instead of copy, replace cp with mv.
To use this in an AppleScript, you can ‘do shell script’.