MacOS – Automatically move all files from within a folder to external SSD, When external SSD is connected

automatorexternal-diskmacos

I have a GoPro 4 which ends up creating very large high quality videos, when connected through USB the Gopro importer app automatically copies the files to a subfolder named by todays date in /users/apple/Pictures/GoPro . Once the files are copied from the GoPro to the /Pictures/GoPro/DATE_Subfolder they are deleted from the GoPro automatically.

These files fill up my macbook hard drive fast so i have brought a external SSD to house all my video files as well as Final Cut Pro X.

What I would like is a script which auto runs on connection of the external SSD, to move the contents of /Pictures/GoPro to /Volumes/Ext_SSD/GoPro then delete the original files from /Pictures/GoPro

Is this possible? I have had a mess around with Automator and can get files to move then delete when the SSD is already connected, but if files are put in the folder when the SSD is disconnected it will not be moved over when the SSD is finally connected again.

Best Answer

You can do this using a launch Agent or Daemon. If you just want this to work for a certain user you would put the below plist in the users launchAgent folder located at

~/Library/LaunchAgents/

Otherwise set it system wide by using a launchDaemon and putting the below plist in the folder located at

/Library/LaunchDaemons/

The below launch plist uses the key "StartOnMount" (any drive being mounted) and watches the file path /Volumes/. Anytime you put in a external drive and it gets mounted to the /Volumes/ folder it will trigger your script or automator file. Just change the path in the below to the location of your script.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>Backup To External</string>
    <key>Program</key>
    <string>/Path/To/Your/backupScript.sh</string>
    <key>StartOnMount</key>
    <true/>
    <key>WatchPaths</key>
    <array>
        <string>/Volumes/</string>
    </array>
</dict>
</plist>

More information from MacTech Pay attention to recipe 7