Skip to content

Instantly share code, notes, and snippets.

@peteburtis
Last active January 4, 2016 06:49
Show Gist options
  • Save peteburtis/8584874 to your computer and use it in GitHub Desktop.
Save peteburtis/8584874 to your computer and use it in GitHub Desktop.
This is an AppleScript that works with FileBase 0.8 (free beta from filebase.co) to download a subset of App.net photos. It remembers which photos it's downloaded before using FileBase's tagging feature, so it's suitable to run frequently (perhaps daily) via a calendar event, cron job, or some other mechanism.
--
-- An AppleScript to download a subset of App.net photos
-- into a folder on your local computer.
--
-- By default, it downloads everything to '~/Pictures/ADN Photos'
--
-- It remembers which photos have been downloaded and
-- which have not (via FileBase's tagging feature),
-- making it suitable to run every day via a calendar
-- event or cron job or equivalent.
--
-- REQUIRES FileBase 0.8 or later.
-- (Available as a free beta at http://filebase.co)
--
-- Download this script, already compiled into a
-- Mac .app here: https://files.app.net/lj7kb-dz
--
-- IMPORTANT: This script may pause for 30 seconds at
-- a time or more as FileBase waits for App.net's
-- rate limit to reset. Especially during the last phase
-- where tags are added to downloaded photos.
--
-------------------------------------------------
-- Customizable parameters: ----------------
-------------------------------------------------
-- The name of a folder within users Pictures folder that will be created to download the photos to.
set destinationFolderName to "ADN Photos"
-- The App.net Type parameters for the photos we're interested in downloading.
-- Defaults to Sprinter Photos, Ohai Photos, and Favd photos.
-- Open FileBase and do a Get Info on a photo to see its type if you'd like to customize.
set allPhotoTypes to {"com.alwaysallthetime.sprinter", "net.app.ohai.journal.photo", "com.yourhead.favd.image"}
-- This is the tag that the script sets on a photo once it's downloaded
-- to ensure it isn't downloaded again.
set downloadedTag to "AppleScript Downloaded"
----------------------------------------------
----------------------------------------------
--
-- The first part of this script deals with getting or creating
-- a folder to download the photos into.
--
-- It defaults to downloading photos to '~/Pictures/ADN Photos',
-- creating the 'ADN Photos' folder if it doesn't exist.
--
tell application "Finder"
-- An existing folder to create our destination folder within.
-- "~/Pictures/"
set containerFolder to folder "Pictures" of (path to home folder)
-- Get a reference to the destination folder, or create if it doesn't exist
-- "~/Pictures/ADN Photos"
try
set destination to (make new folder at containerFolder with properties {name:destinationFolderName}) as alias
on error
set destination to folder destinationFolderName of containerFolder as alias
end try
end tell
--
-- Now that the folder is found or created and we have an alias of it, here's
-- where the meat of the script begins.
--
-- We get all the photos of the proper type in our storage, iterate through list
-- list keeping only photos that haven't been tagged 'Script Downloaded',
-- download just those new photos, and then add the 'Script Downloaded' tag
-- to them so we don't download them again.
--
with timeout of 1200 seconds
-- Give ourselves 20 minutes (1200 seconds) to do everything
-- (Downloading all these photos can take a while)
tell application "FileBase"
wait for load -- Waits until FileBase has completely downloaded the list of files available from App.net
-- Create a list called allPhotos, iterate over over our list of types to fill it.
set allPhotos to {}
repeat with photoType in allPhotoTypes
set selectedPhotos to (adnFiles where adn type is photoType)
set allPhotos to allPhotos & selectedPhotos
end repeat
-- Create a new list called undownloadedPhotos. Iterate over all
-- photos, checking whether or not each one has the 'Script Downloaded'
-- tag set. If the tag isn't set, we haven't downloaded this photo before, so add
-- it to the undownloaded list.
set undownloadedPhotos to {}
repeat with photo in allPhotos
if tags of photo does not contain downloadedTag then
set end of undownloadedPhotos to photo
end if
end repeat
-- Have FileBase download the photos to our destination folder
download undownloadedPhotos to destination
-- Finally, add the 'Script Downloaded' tag to each photo we've just downloaded
-- so it won't be downloaded again on future runs of this script.
repeat with photo in undownloadedPhotos
add tag downloadedTag to photo
end repeat
end tell
end timeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment