Automatically sync folders on MacOS
This repository contains an AppleScript for automating folder synchronization between between folders on macOS.
The script ensures that the folders are kept in sync every time the external drive is connected.
- Copies new files from the source folder to the destination folder
- Skips files that already exist in the destination folder
- Deletes files in the destination folder that no longer exist in the source folder
- macOS
- AppleScript
- launchd (for automation)
Edit the SyncMyFiles.applescript
file to specify the paths of your source and destination folders.
-- Define source folder on the internal drive
set sourceFolder to "/source"
-- Define destination folder on the external drive
set destinationFolder to "/destination"
Compile the modified AppleScript as an SyncMyFiles.scpt
file on your Mac.
Copy the SyncMyFiles.plist
file to ~/Library/LaunchAgents/
to automate the script execution when the external drive is connected.
cp ~/code/macos-folder-sync/SyncMyFiles.plist ~/Library/LaunchAgents/
Run the following command in Terminal to load the SyncMyFiles.plist
file:
launchctl load ~/Library/LaunchAgents/SyncMyFiles.plist
- Connect your external drive.
- The script should run automatically, syncing the specified folders.
- That's it.
osascript ~/code/macos-folder-sync/SyncMyFiles.scpt
- Confirm start on-run
MIT