I'm just appalled at how crude Photos (still) is.
Once you've entered the Find field you can't get out with the keyboard.
There's no way to select an album with just the keyboard – even with full keyboard access turned on.
As far as I can see there's no way to script the selection of an album to make it active.
Home and End don't work in slideshow view.
On and on...
At least it's scriptable (after a fashion).
I'm writing a script for someone who wants to export items from the Last Import album.
It would help to be able to make it active, so she can see what's in it before running the export.
It would appear that System Events is the only way to get there.
-------------------------------------------------------------------------------------------
# dCre: 2017/02/13 20:00
# dMod: 2017/02/13 20:40
# Appl: Photos and System Events
# Task: Select Last Import Album
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Select, @Last_Import, @Album
-------------------------------------------------------------------------------------------
tell application "System Events"
tell application process "Photos"
tell (first window whose subrole is "AXStandardWindow")
tell outline 1 of scroll area 1 of group 2 of splitter group 1
tell (first row where its UI element 1's name is "Last Import")
set value of attribute "AXSelected" to true
end tell
end tell
end tell
end tell
end tell
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
# dCre: 2017/02/13 20:59
# dMod: 2017/02/13 21:08
# Appl: Photos
# Task: Export Last Imported Album Images to a Date-Stamped Folder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Photos, @Export, @Last_Imported, @Album, @Images, @Date-Stamped, @Folder
-------------------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
-------------------------------------------------------------------------------------------
set targetDir to "~/Amazon Drive"
set dateStampFormat to "y-dd-MM HH.mm.ss"
-------------------------------------------------------------------------------------------
set theNSString to current application's NSString's stringWithString:targetDir
set targetDirPath to theNSString's stringByExpandingTildeInPath() as string
set dateStamp to my makeFormattedDateStr:(current date) usingFormat:dateStampFormat
set newFolderName to "Photos Export " & dateStamp
set newFolderPath to targetDirPath & "/" & newFolderName
its createDirectoryAtPath:newFolderPath
set exportFolderAlias to alias POSIX file newFolderPath
tell application "Photos"
set lastImportAlbum to last import album
tell lastImportAlbum
set lastImportedMediaList to its media items
end tell
if lastImportedMediaList ≠ {} then
export lastImportedMediaList to exportFolderAlias with using originals
end if
end tell
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
# Will create intermediate directories as necessary.
on createDirectoryAtPath:thePath
set {theResult, theError} to current application's NSFileManager's defaultManager()'s createDirectoryAtPath:thePath withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
if not (theResult as boolean) then
set errorMsg to theError's localizedDescription() as text
error errorMsg
end if
end createDirectoryAtPath:
-------------------------------------------------------------------------------------------
on makeFormattedDateStr:theDate usingFormat:formatString
if class of theDate is date then set theDate to my makeNSDateFrom:theDate
set theFormatter to current application's NSDateFormatter's new()
theFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"en_US_POSIX")
theFormatter's setDateFormat:formatString
set theString to theFormatter's stringFromDate:theDate
return theString as text
end makeFormattedDateStr:usingFormat:
-------------------------------------------------------------------------------------------
on makeNSDateFrom:theASDate
set {theYear, theMonth, theDay, theSeconds} to theASDate's {year, month, day, time}
if theYear < 0 then
set theYear to -theYear
set theEra to 0
else
set theEra to 1
end if
set theCalendar to current application's NSCalendar's currentCalendar()
set newDate to theCalendar's dateWithEra:theEra |year|:theYear |month|:(theMonth as integer) ¬
|day|:theDay hour:0 minute:0 |second|:theSeconds nanosecond:0
return newDate
end makeNSDateFrom:
-------------------------------------------------------------------------------------------