I'm pretty sure my question is just a general syntax question, but including specific context in case it's relevant:
There's a Mac app called SwitchResX which lets you do cool things like create and use custom resolutions on Mac monitors. It has a background process called "SwitchResX Daemon" which is AppleScriptable.
Among other things:
application
(class) has one or moredisplay
elementsdisplay
(class) has one or moremode
elementsmode
(class) has properties likeheight
,width
(integers),frequency
(real),valid
(boolean), etc.
I'm having two related problems:
Problem 1: whose/where X is in {...}
tell application "SwitchResX Daemon"
set theDisplay to the second display
set theModes1 to theDisplay's every mode where it is valid and ((its width is 3008) or (its width is 2560)) --> {mode 8 of display 2, mode 12 of display 2} = expected and desired result
set theModes2 to theDisplay's every mode where it is valid and (its width is in {3008, 2560}) --> …error: Can’t make {3008, 2560} into type specifier.
end tell
I use if
statements like if width is in {3008,2560} then ...
a lot. Can the is in {...}
condition not be used in a whose
/where
clause, or do I just the syntax wrong?
Problem 2: I have a need to split the filtering in at least one situation. So...
tell application "SwitchResX Daemon"
set theDisplay to the second display
set theModesAllValid to theDisplay's every mode where it is valid --> {……, mode 8 of display 2, mode 12 of display 2, ……} = expected and desired result
set someModes1 to theModesAllValid's first item where ((its width is 3008) or (its width is 2560)) --> mode 8 of display 2 = expected and desired result
set someModes2 to theModesAllValid's first item where (its width is in {3008, 2560}) --> same error as problem 1 above
set someModes3 to theModesAllValid's every item where ((its width is 3008) or (its width is 2560)) --> error noted below**
set someModes4 to theModesAllValid's every item where (its width is in {3008, 2560}) --> error noted below**
end tell
-- **error = "Can’t get {……, mode 8 of display 2 of application "SwitchResX Daemon", mode 12 of display 2 of application "SwitchResX Daemon", ……} whose width of it = 3008 or width of it = 2560."
So someModes1
(using first item
instead of every item
) works -- similar to theModes1
in Problem 1 (except item instead of list, as expected). And someModes2
gives the same error as theModes2
(so, consistent at least).
But then I would expect someModes3
and someModes4
to give the same results as Problem 1, but here the every
breaks it somehow. Why is that? And even if there's no solution to Problem 1 (meaning someModes4
won't work), is there some way to break the filtering up into two steps for some derivative of someModes3
to work?
Thanks in advance for any help!