1
votes

Can anyone explain why the following piece of Applescript code returns an error:

tell application "Photos"
    set idList to {"v3xzjwPQT0y8a844gLHLHWg", "v3w3twPQT0y%%844gLgf4Wg"}
    set itemList to every media item in application "Photos" where its id is in idList
    log (count of itemList)
end tell

The error is:

error "Photos got an error: Can’t make {\"v3xzjwPQT0y8a844gLHLHWg\", \"v3w3twPQT0y%%844gLgf4Wg\"} into type specifier." number -1700 from {"v3xzjwPQT0y8a844gLHLHWg", "v3w3twPQT0y%%844gLgf4Wg"} to specifier
3
Seems to be a bug. Submit a bug report to Apple. By the way: In the third line delete in application "Photos" because there is a global application tell block. But even without this double reference the script throws an error - vadian

3 Answers

0
votes

There is no error in this line of code using OSX 10.9 and iPhoto. Perhaps something changed in "Photos"/10.10?

In any event, do you still get the error if you move the line of code

set idList to {"v3xzjwPQT0y8a844gLHLHWg", "v3w3twPQT0y%%844gLgf4Wg"}

to just before the Tell "Photos" block? The error is saying "Photos" got the error trying to make the idList. So try defining the idList without Photos. I would think the list could be defined without telling Photos to do it.

0
votes

I have the same issue. My goal is to get all images that are not in a certain album. The error rises in the line

set itemList to every media item in application "Photos" where its id is in idList

Also this one-liner results in an error

set itemList to every media item in application "Photos" where its name is in {"bla"}

What works is the following line

set itemList to every media item in application "Photos" where its name is "bla"

But that does not solve the problem. Maybe someone has a suggestion how to do it.

0
votes

That feature does seem to be broken in Photos 4. You can work around it in a couple of ways. If your list is simple and fixed you can build up a command using or statements like so:

set itemList to every media item whose id is "wi9HoFU0SKCDianaQBtJBg" or id is "DT29HF1lRgCKOaIZFHoHrQ"

If you need something more flexible, you can use a repeat loop and build up the list through individual searches:

set idList to {"wi9HoFU0SKCDianaQBtJBg", "DT29HF1lRgCKOaIZFHoHrQ"}
tell application "Photos"
    set newList to {}
    repeat with thisID in idList
        set anItem to (first media item whose id is thisID)
        copy anItem to end of newList
    end repeat
end tell