AppleScript search and display photos

Having read several basic guides to AppleScript and got several simple scripts working successfully I am stuck on what I wanted to do.


I am using NeoFinder to pass the name of a file to Photos (it does exist there) for editing. The Photos Dictionary says that using the 'search for' command operates precisely the same way as typing the text in the Photos search window. I can pass the text from NeoFinder and get Photos to display it to conform that it is there, and I can use that in a simple command (search for inputname) that appears to work. But even though Photos comes to the front it does not display the search results.


The spotlight command is then needed to display the found image, but the using 'media item' as the selection just displays the an item from the main catalog, not from the search items (supposedly) retrieved. Using 'spotlight selection' does display the last image selected, but I want to display the first image from the search result.


Any suggestions?

Posted on Jan 23, 2021 6:20 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 23, 2021 9:17 AM

I have solved my own question. The following script works.


-- This script takes a selected image name from NeoFinder and opens that image in Photos. No error checking -- is done at this stage. It is assumed that the image exists in Photos.




tell application "NeoFinder"


activate


end tell




-- Copy selected text from the active app to clipboard:


tell application "System Events" to keystroke "c" using {command down}




tell application "Photos"


copy (the clipboard) to inputname


set searchList to search folder "library" for inputname


spotlight item 1 of searchList


end tell

Similar questions

1 reply
Question marked as Top-ranking reply

Jan 23, 2021 9:17 AM in response to melodeonman

I have solved my own question. The following script works.


-- This script takes a selected image name from NeoFinder and opens that image in Photos. No error checking -- is done at this stage. It is assumed that the image exists in Photos.




tell application "NeoFinder"


activate


end tell




-- Copy selected text from the active app to clipboard:


tell application "System Events" to keystroke "c" using {command down}




tell application "Photos"


copy (the clipboard) to inputname


set searchList to search folder "library" for inputname


spotlight item 1 of searchList


end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript search and display photos

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