MacOS Automator: Select different files from Folder structure and move to folder

I have a bunch (roughly 10.000) of Images named "XXXXX.psd", where X is a number. Sometimes the name string is shorter (XXX.psd).

I also have a List which tells me which of these images I need, roughly 180 images every two weeks or so. I'd like to make an automation that takes said list and then automatically copies the needed images into a separate folder.

Any help is appreciated, I kno nothing about applescript or javascript, but am willing to try it :P

PS: The images are in separate folders. The list is a pdf but i managed to extract it into an xlsx/table, and could also just have it in plain txt.

You could write a shell script that takes each line from a plain text file, checks if the file exists, then moves/copies it to your chosen location.

The plain text file should look something like this:

/Users/username/Pictures/Projects/00001.psd
/Users/username/Pictures/Projects/00002.psd
/Users/username/Pictures/Projects/Updated/00003.psd
/Users/username/Pictures/Projects/00004.psd

etc. Each file name should be unique, i.e. you can only have one file named 00001.psd.

This works for me:

  • Create an empty text file somewhere useful, like in your /Users/username/ directory.
  • Edit the file and put this in it:
#!/bin/bash

input=$1
dest=$2

while IFS= read -r line
do
  if [ -f "$line" ]; then
    cp $line "$dest"
else 
    echo "$line does not exist."
fi
done < "$input"
  • Rename the file to something like "move_files.sh" (the .sh extension is important).
  • Launch a Terminal window. You should be in your home folder by default, i.e. /Users/username/. If you aren't already in that location you'll need to cd to it, i.e. cd /wherever/the/file/is/.
  • You may not need to do this, but can't hurt: chmod u+x move_files.sh. That makes it executable.

You use the script like this: move_files.sh /Users/username/Downloads/Work/files.txt /Users/username/WorkInProgress/ The first parameter is the location and name of the plain text list of files. The second param is the destination. Be sure to add a trailing slash /.

The script is written to copy the files first rather than move them, so if it works for you, you can change the cp command on line 9 to mv.

Hope this helps.

MacOS Automator: Select different files from Folder structure and move to folder
 
 
Q