Manage the macOS Photos library via AppleScript/JXA: search, export, and create albums.
Use Cases
- The user says "Help me find the photos I took in Tokyo last year" or "Where are my recent screenshots"
- The user says "Export all the photos in this album"
- The user says "Create an album called Travel"
Execution Method
Search Photos
osascript -e '
tell application "Photos"
set results to (media items whose description contains "Tokyo" or name contains "Tokyo")
set output to ""
repeat with photo in (items 1 thru (min of {20, count of results}) of results)
set output to output & (id of photo) & " | " & (filename of photo) & " | " & (date of photo) & linefeed
end repeat
return output
end tell'
Search by date range
osascript -e '
tell application "Photos"
set startDate to date "2025-12-01"
set endDate to date "2025-12-31"
set results to (media items whose date ≥ startDate and date ≤ endDate)
return (count of results) & " photos found"
end tell'
Get album list
osascript -e '
tell application "Photos"
set output to ""
repeat with a in albums
set output to output & (name of a) & " (" & (count of media items of a) & " items)" & linefeed
end repeat
return output
end tell'
Create album
osascript -e '
tell application "Photos"
make new album named "旅行 2026"
end tell'
Export photos
osascript -e '
tell application "Photos"
set targetAlbum to album "旅行 2026"
set exportPath to POSIX file "/Users/me/Desktop/export/"
export (media items of targetAlbum) to exportPath
end tell'
Output Specifications
- Search results display thumbnail information (file name, date, count)
- Confirm the count and destination directory before export operations
- Do not delete photos; only read and export