Skip to content

Instantly share code, notes, and snippets.

@tylerhall
Last active April 22, 2019 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerhall/ed31bde58fc28554a7fbba426e69bc09 to your computer and use it in GitHub Desktop.
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.
# Download photos from the remote server
do shell script "rsync -avz --delete -e 'ssh -p 22' user@domain.com:/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/ user@domain.com:/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