Last active
June 22, 2021 17:48
-
-
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.
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
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