Add Face to Photo

Good day - within Mac Photos, I would like to make a service that would perform an action similar to clicking the “+Add Faces” button within the Info box of a selected photo. I have a lot of pictures to catalogue, and feel that a service called from a keyboard shortcut would work most efficiently.

Thanks for any guidance you could provide.
Brian

You may try :

tell application "Photos"
	set AddFaces_loc to localized string "IPXMetadataEditorFacesView_AddFaces" from table "IPXMain"
end tell

tell application "System Events" to tell process "Photos"
	set frontmost to true
	keystroke "i" using {command down}
	repeat 20 times
		delay 0.1
		set theSubroles to subrole of every window
		if theSubroles contains "AXDialog" then exit repeat
	end repeat
	repeat with i from 1 to count theSubroles
		if theSubroles's item i is "AXDialog" then exit repeat
	end repeat
	tell window i
		set {xWindow, yWindow} to its position
		value of every static text
		set {xText, yText} to position of first static text whose value is AddFaces_loc
		--do shell script "/Users/admin/bin/cliclick c:" & (xWindow + xText) div 2 & "," & yText # Was here
	end tell
end tell
do shell script "/Users/admin/bin/cliclick c:" & (xWindow + xText) div 2 & "," & yText # Better here

cliclick is available for free from : http://www.bluem.net/en/mac/cliclick/versions/

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) jeudi 5 mai 2016 16:51:15

Thank you so much for writing this!! It is very much appreciated!

I have opened Photos, and selected a picture. When I run the script I receive the following error message:

System Events got an error: Can’t get static text 1 of window 1 of process “Photos” whose value = “Add Faces”. Invalid index.

Do you have any ideas as to what am I doing incorrectly?

Thank you!
Brian

No, I have no idea.

Here the events log is :

tell application "Photos"
	localized string "IPXMetadataEditorFacesView_AddFaces" from table "IPXMain"
		--> error number -1708
	«event ascrgdut»
		--> error number -1708
	localized string "IPXMetadataEditorFacesView_AddFaces" from table "IPXMain"
		--> "Ajouter des visages"
end tell
tell application "System Events"
	set frontmost of process "Photos" to true
	keystroke "i" using {command down}
	get subrole of every window of process "Photos"
		--> {"AXStandardWindow"}
	get subrole of every window of process "Photos"
		--> {"AXDialog", "AXStandardWindow"}
	get position of window 1 of process "Photos"
		--> {818, 273}
	get value of every static text of window 1 of process "Photos"
		--> {"DSC_0043.NEF", "15 janvier 2016   16:15", "Ajouter des visages", "3 sur 3"}
	get position of static text 1 of window 1 of process "Photos" whose value = "Ajouter des visages"
		--> {865, 530}
end tell
tell current application
	do shell script "/Users/admin/bin/cliclick c:841,530"
		--> ""
end tell

Is the local dialog allowing us to activate the « Add Faces » feature revealed by the script ?
What is the events log on your machine ?
“Ajouter des visages” is the localized string for the English “Add Faces”.

Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) lundi 9 mai 2016 16:10:07