Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active June 22, 2021 17:48
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 henrik/af643c1794831f1be24d3a3390eeb412 to your computer and use it in GitHub Desktop.
Save henrik/af643c1794831f1be24d3a3390eeb412 to your computer and use it in GitHub Desktop.
Photos.app: Rename albums to zeropad numbers. Use case: Relying on sorted events and migrating from iPhoto which sorted "100" after "2" to Photos which didn't.
tell application "Photos"
repeat with theAlbum in albums of folder "Events"
set theName to name of theAlbum
-- Zeropad initial numbers, e.g. turning "12.3 Hi" into "0012.3 Hi".
set newName to (do shell script "ruby -e 'n = ARGV.first; num, rest = n.split(%{.}, 2); puts num.match?(/\\A\\d+\\z/) && rest ? [ num.rjust(4, %{0}), rest ].join(%{.}) : n' " & (quoted form of theName))
set name of theAlbum to newName
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment