You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript Photos App copy filename to textedit or Numbers

Problem: I've imported a large image library into Photos (using iCloud library). However i know a number of photos or videos didn't get imported ~ not sure why. To troubleshoot I want to compare the 2 sets of filenames in Numbers/Excel (library names before i imported & the actual names in the Photo library).


I'm trying to leverage AppleScript to help me out. Should be simple enough to grab the file name for selected images or an album name. I just don't have enough experience to figure it out.


The following will get me the image name of the first selected image, but how do i get a selection of, say, 200 and then post those results in Numbers/Excel or even Textedit?


tell application "Photos"

set theSelecteMediaItem to item 1 of (get selection) -- the first selected photo

set theFilename to filename of result as text

end tell


Anyone with some applescript experience that could post a solution?? thanks folks.

MacBook Air (13-inch Mid 2013), macOS Sierra (10.12.2)

Posted on Feb 5, 2017 12:11 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 6, 2017 8:09 PM

Hi WildWilly,


I'm not sure how you want to pass the filenames to Text Edit or other apps.


This script will copy the filenames of the selected photos to the pasteboard as a long string, so you can paste them into any editor after running the script:


tell application "Photos"


activate


set theFilenames to {}


set imageSel to (get selection) -- get the selected image


repeat with im in imageSel

set theFilenames to the ({filename of im} & {" "} & theFilenames)

end repeat




set the clipboard totheFilenames as string


return theFilenames

end tell


léonie

3 replies
Question marked as Top-ranking reply

Feb 6, 2017 8:09 PM in response to WildWillyD

Hi WildWilly,


I'm not sure how you want to pass the filenames to Text Edit or other apps.


This script will copy the filenames of the selected photos to the pasteboard as a long string, so you can paste them into any editor after running the script:


tell application "Photos"


activate


set theFilenames to {}


set imageSel to (get selection) -- get the selected image


repeat with im in imageSel

set theFilenames to the ({filename of im} & {" "} & theFilenames)

end repeat




set the clipboard totheFilenames as string


return theFilenames

end tell


léonie

Feb 6, 2017 8:14 PM in response to léonie

Leonie,


Thanks! That worked like a charm. I modified it just slightly to include a carriage return, such that when i paste in Excel, each image name gets pasted in a cell. Tested with multiple albums, with 100's to 1000's of images. Worked flawlessly.


Modification:


tell application "Photos"

activate


set theFilenames to {}


set imageSel to (get selection) -- get the selected image


repeat with im in imageSel

set theFilenames to the ({filename of im} & {"

"} & theFilenames)

end repeat


set the clipboard to theFilenames as string


return theFilenames


end tell

AppleScript Photos App copy filename to textedit or Numbers

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.