dbrewood. The first AppleScript can only return one photo. The Find Photos action can find and return multiple photos.
Using one of multiple photos returned by the Find Photos action would not be a good solution, because the photo may have a keyword Processed.
I think the best approach might be to add additional criteria (e.g. image width) to the Find Photos action. The actual criteria would be gotten from the AppleScript and used in the Find Photos action. The criteria used would be based on your analysis of multiple photos returned by the Find Photos action. However, this probably would not work if the duplicates are exact duplicates of one another.
dbrewood. Just to make sure, I downloaded and retested my latest shortcut without issue. However, I only have perhaps 30 photos in the Photos App.
To troubleshoot this issue, I suggest you add a View Content Graph action in the shortcut after the Find Photos action. This will show the actual photos returned. In the following, the Find Photos action only returned one photo.
A possible solution to the above situation is to change the second AppleScript as shown below. The file name with extension would be gotten from the first AppleScript. This is a bit of a kludge, because there might be an entirely different photo with the file name “County Courthouse.heic” and that could be the photo that the shortcut would post to Mastodon.
tell application "Photos"
set keywords of every media item whose filename is "County Courthouse.jpg" to "Processed"
end tell
Another alternative is to change the second AppleScript to that shown below, and this would change both duplicates of “County Courthouse.jpg” to Processed. It would also change “County Courthouse Winter.jpg” and “County Courthouse.heic” to processed. Given the ultimate purpose of the shortcut, this might be a good approach.
tell application "Photos"
set keywords of every media item whose filename begins with "County Courthouse" to "Processed"
end tell
I still think though that is multiples are detected, pick one and work with that, allow that to be processed which will reduce the multiples by one, and if the same photo is selected at another time, process it similarly so the number of multiples are reduces each time that ,name’ is processed?
Or does the duplication ‘situation’ prevent an actual match being made?
If it is the latter then I agree all of those should be marked ‘processed - duplicate’ and when I start to run out oof photos to process I can look to handle those manually.
I’ve 2083 favourites out of 6624 photos in my library so a way to go I guess
I still think though that is multiples are detected, pick one and work with that, allow that to be processed which will reduce the multiples by one,… If it is the latter then I agree all of those should be marked ‘processed - duplicate’ and when I start to run out oof photos to process I can look to handle those manually.
For the most part, that is how the following shortcut works. However, all photos that begin with the file name are marked as “Processed” instead of “Processed - Duplicate” I’ve only spent a limited time with this shortcut, but it did work in limited testing.
I still think though that is multiples are detected, pick one and work with that, allow that to be processed which will reduce the multiples by one, and if the same photo is selected at another time, process it similarly so the number of multiples are reduces each time that ,name’ is processed?
@peavine Thanks for that. I’ve just run the latest shortcut above. I assume my routines should start after your ‘selector’ using the ‘Get First Item from * Photos’ as the source?
Which seems to show that it is not only favourites which are being scanned? I’ve checked the images and processed has been assigned to both photos, the favourite and non-favourite?
In my revised shortcut, I would probably put your routines after the Find Photos action. The Get First Item action wasn’t really necessary, so I deleted it. Your routines could also be put at the very end of the shortcut. This depends on when you actually want to set the keywords of the photos to “Processed”.
@peavine Thanks for that, it is greatly, appreciated. Just completed some texting and on duplicated being found the ‘processed’ keyword was indeed applied to the favourites only.
Hopefully that totally awesome bit of coding will work very well. I’ll look to incorporate it into my Shortcut as soon as I can. It’s our Wedding Anniversary today so coding time will be limited.
I’ll come back to you if I have any issues, but I think I’ll be okay. Once again (as always) my greatest thanks.
dbrewood. Congratulations on your wedding anniversary. I trust you’re having a great day.
It’s good news that we’ve found a solution that is workable and that will allow you to move on with the rest of your shortcut. Our solution is far from perfect, but I suspect it will do the job until Apple adds the ability to get and set keywords in a shortcut.
I had some free time today and looked into whether a date could be used as an additional filter in the Run AppleScript and Find Photos actions. I’m uncertain if the date returned by the AppleScripts and the Find Photos action are of the same property, although the shortcut seemed to work as expected in limited testing. It would almost certainly be significantly slower, though.
@peavine That is superb, thanks for the extra effort you’ve put in. Your new shortcut seems to work well indeed.
I’m having a problem adding it to my main shortcut though. It seems I have an issue with one of the variables
In the above I get:
A - Gives the file name - OK
B - Gives the date - OK
C - Gives the date - Wrong…
D - I think ‘The Item from List’ is wrong somehow.
I’ve looked to re-add / edit / copy & paste (from your shortcut) ‘D’ so that it returns the right information but I must be missing something as I just can’t get it to give what is needed.
Good to hear that. I installed a fresh version of the shortcut and got the expected result. I’m still torn in shortcuts between manual and magic variables.
Yep it does look like it was a variable Issue. I’ve seen problems with manual and magic variables before. I’m just glad it fixed it.
Only one last issue to resolve now. When setting the keyword (at the end of my shortcut) it seems to run for a long time (typically 75 seconds), although the keyword is applied nigh on instantly - checked by watching a smart album populate in the Photos app.
Eventually it errors out with:
You mentioned earlier that you have over 6,000 photos in your Photos app. In contrast, I have 10 photos. A concern I had with both scripts–but especially with the second script–was the amount of work the second AppleScript has to do.
I would suggest that you put a Stop this Shortcut action before the last Run AppleScript action and retest. This is just to make sure that AppleScript is the culprit. If it s in fact the culprit, let me know, and I’ll try to rewrite the AppleScript action.
Just as a point of information, the first AppleScript finds a matching photo then stops. So, it should be reasonably quick. The second AppleScript gets and tests favorite/name/date of all 6,000 photos, which of course takes some time.
It is definitely the second script which has the time issue. I just ran the shortcut you created with the new Apple Script in (after I took out my ‘end shortcut’ I added while debugging the earlier issues I had - I forgot that was still in place).
I had the same timing issues, so it is definitely the second script which has the issues.
The first script is lighting fast finishing in seconds, the second one has the issues stated. I’ve no ideas what you can do at all to resolve the run time issue. Good luck indeed!
I made a simple optimization to the shortcut, which reduced the timing result with 57 photos by about 75 percent. I left the timing actions in place, so the timing result will be shown when the shortcut completes. Please let me know what that is (if the shortcut doesn’t error). I’ll look at additional optimizations later today. Is the earlier shortcut that doesn’t have the date filter much faster? Perhaps your reference to “The first script” refers to the first shortcut, in which case you have answered my question.
Way faster as you can see. One heck of an awesome job of optimising. I’ll let you do the additional work. Well done!
The first script was referencing the first Apple Script, which seems to work well enough in the current shortcuts. Sorry if I’m being a bit unclear today, it’s a day of migraines
Oh and I forget to say we had a great anniversary day
@peavine I wanted to feed back… I build the new optimised Apple Script into the shortcut and it typically completes the marking process in between 2.8 and 5.3 seconds. No errors generated so it looks pretty good and I don’t think any further optimisation is needed? If you do wish to do any more work on it, then it’s your call of course LOL
One thing I would like to ask, What regex would be used to allow only A-z, A-Z, 0-9 characters? I’ve some characters coming out in addresses such as - and ’ I want to get rid of. Thanks again for all your assistance.
dbrewood. Thanks for the feedback, which is great news. That timing result for a shortcut that gets and then applies three tests to over 6,000 photos seems reasonable.
FWIW, the following shortcut simply works by setting the keyword of the photo identified in the first Run AppleScript action to “Processed”. This shortcut is about 25 percent faster as compared with the earlier optimized version. However, duplicates of a photo will not be set to “Processed”, and this would seem to make the shortcut unusable given its intended purpose. Of course, you may want to build into your final shortcut a Skip This Photo option, in which case this shortcut might be considered. Anyways, having a few additional approaches to consider is always a good thing, and I do like this new version for its simplicity.
As regards the regex, you can specify either characters to include or characters to remove, and the following shortcut has three examples. You may need to daisy-chain two of these to get desired results. For example, simply deleting a dash might not work well.
@peavine Thanks muchly. The ‘Final Optimisation’ runs in around 0.05 to 0.06 of a second Totally awesome. I think I’m happy it is only the selected photo which is being marked as ‘Processed’.
I’m more than happy for the duplicates not to be marked as processed, as those can again go through possible processing at a later date. If I understand this, then this is the ideal situation.
Thanks for the regex examples those will indeed be very useful and do clarify the usage. Hmmm, The first regex is great but I want to retain the hash character? - Yay I worked it out: [^0-9a-z# ]
I’ll do some more testing but this is now looking superb! Thanks as always.