Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator workflow setup help

Hello, I need some help trying to accomplish a tedious task using Automator.


I have a folder located on an external drive that contains 500+ video files. I wish to use Automator to create a task that opens the folder, creates a new enclosing folder for each individual video file, and names each enclosing folder the same name as the video file (minus the extension of course).


So, as an example, starting with...


/Movies

Movie1.mkv

Movie2.mkv

Movie3.mkv


I'd like to end up with...


/Movies

/Movie1

Movie1.mkv

/Movie2

movie2.mkv

/Movie3

movie3.mkv


I would appreciate anyone who could help me with the precise steps needed to set this up in Automator (or other simple solution, if available).


Thank you in advance.





MacBook Pro

Posted on Mar 31, 2020 1:39 PM

Reply
Question marked as Best reply

Posted on Mar 31, 2020 9:03 PM

The following Automator workflow will prompt for the folder on your server, and the make new folders in that selected folder for the basename of each file in it — before moving those respective files into their own named folder. I tested this with my Synology Diskstation, and the Automator workflow was run on Mojave 10.14.6 with success.


The replacement script for the Run Shell Script boilerplate is as follows. It is written for the zsh shell and is quite quit. You can adjust the different video file extensions that it may encounter.


DIR="${1}"

for f in ${DIR}/*.(mkv|mp4|m4v|mov|avi)(.); do
    newdir=${f:a:t:r}
    fname=${f:a:t}
    # make the dir if it does not exist
    [[ -d $newdir ]] || mkdir $DIR/${newdir}
    mv ${f} ${DIR}/${newdir}/${fname}
done



Similar questions

3 replies
Question marked as Best reply

Mar 31, 2020 9:03 PM in response to rockhound76s

The following Automator workflow will prompt for the folder on your server, and the make new folders in that selected folder for the basename of each file in it — before moving those respective files into their own named folder. I tested this with my Synology Diskstation, and the Automator workflow was run on Mojave 10.14.6 with success.


The replacement script for the Run Shell Script boilerplate is as follows. It is written for the zsh shell and is quite quit. You can adjust the different video file extensions that it may encounter.


DIR="${1}"

for f in ${DIR}/*.(mkv|mp4|m4v|mov|avi)(.); do
    newdir=${f:a:t:r}
    fname=${f:a:t}
    # make the dir if it does not exist
    [[ -d $newdir ]] || mkdir $DIR/${newdir}
    mv ${f} ${DIR}/${newdir}/${fname}
done



Apr 1, 2020 12:14 PM in response to VikingOSX

This worked perfectly. Thank you very much, VikingOSX!


EDIT: In case this helps other users, this was confirmed to work using Automator on Catalina 10.15.3, using folders located on my Desktop and on my Synology Diskstation.


Additionally, I tested this using a folder of .mp3s (appending VikingOSX's script to add the .mp3 file extension), so extensibility seems to work as well.


One thing I did notice, is that when running on a iCloud Desktop folder, for which contents of the folder were not locally stored (i.e. files have the iCloud icon next to them), the script still worked but stopped after the first file. So best to use after folder contents are downloaded locally.

Automator workflow setup help

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.