Last active
April 22, 2019 21:16
-
-
Save tylerhall/ed31bde58fc28554a7fbba426e69bc09 to your computer and use it in GitHub Desktop.
AppleScript to rsync images from a remote server and import them into Photos.app. Cleans up after itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Download photos from the remote server | |
do shell script "rsync -avz --delete -e 'ssh -p 22' [email protected]:/path/to/photos/ /Users/username/Pictures/SomeFolder/" | |
set folderPath to alias "Users:username:Pictures:SomeFolder" | |
set imageList to getImageList(folderPath) | |
# Import the list of photos into Photos.app | |
if number of items in imageList is greater than 0 then | |
tell application "Photos" | |
activate | |
delay 2 # Give Photos.app time to open | |
tell application "Finder" to set visible of process "Photos" to false | |
set theAlbum to album named "SomeAlbumName" | |
import imageList into theAlbum | |
# Clean up after ourselves | |
do shell script "rm /Users/username/Pictures/SomeFolder/*" | |
# Delete the photos from the server now that we've imported them | |
do shell script "rsync -avz --delete -e 'ssh -p 22' /Users/username/Pictures/SomeFolder/ [email protected]:/path/to/photos" | |
tell application "Finder" to set visible of process "Photos" to false | |
end tell | |
end if | |
on getImageList(aFolder) | |
tell application "Finder" to set theFiles to every file of aFolder | |
set imageList to {} | |
repeat with i from 1 to number of items in theFiles | |
set thisItem to item i of theFiles as alias | |
set the end of imageList to thisItem | |
end repeat | |
imageList | |
end getImageList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment