I have up to three displays and I use them in specific manners, but I don't always have three. Sometimes I only have two, or just one. They have different resolutions, and I generally don't change resolutions.
Desire: How can I get the Applications Palette to move to the upper-left of the right-most display?
Displays are indexed 1, 2, 3... left-to-right -- but you can also use -1, -2, -3... to go right-to-left. So %ScreenVisible%-1% will always get you the bounds of the rightmost screen, however many are connected.
The Applications Palette is a Keyboard Maestro engine, but hiding/showing it doesn't gives us a "Last Engine Window ID" we can use But we can get it with AppleScript -- it's the Engine window named "Applications" -- then use the ID in a "Move Window" action.
I only have one screen, so it's all rather theoretical -- but it does work on a single screen!
Note that if you ever pop up a "Custom HTML Prompt" window or similar titled "Applications" there's a chance of confusion, although the App Palette should always be the first item in the list. It's a pretty slim chance so I haven't included any error checking, but bear it in mind if the macro misbehaves...
Observation: I have noticed sometimes when I restart with 3 displays, the numbering of displays does not work consistently. To explain, let's say I have an external ViewSonic Display and an external Dell Display connected to my MacBook Pro. I see the following two situations even though I do not change the settings:
#
Restart 1
Restart 2
0
MacBook
MacBook
1
MacBook
MacBook
2
Dell
ViewSonic
3
ViewSonic
Dell
Fortunately, I do not reboot often and I can use a persistent variable to address this issue, which I can manually update at startup time.
The middle column is the key. So I can compute the ordering as long as the widths are different and I know the width of the MacBook and one of the other two. If they're the same, it does not matter. For my situation this can be hardcoded since I always have the middle screen resolution set to 1920x1080 (used for streaming broadcasting).
KM's indexing is taken directly from the OS, and so should be the same as the display arrangement shown in Display Preferences/Settings. Are you not seeing that?
Macs generally remember screen layouts and automatically apply the last arrangement used for a set of connected screens when they are reconnected. It may be that you have two "saved" arrangements -- one for when it connects to the ViewSonic then the Dell, another for the Dell then the ViewSonic -- and you're falling victim to a connection timing issue.
There might also be a problem with sleep/wake, if it is a timing issue. So I'd look at doing a check every time the macro is run by:
Getting %Screen%All% -- one screen frame per line, left-to-right
Counting down the list to get the number of the line whose width value is 3360 -- call it n
Using that number as the index in the first action above -- %ScreenVisible%n%
That'll work as long as the Dell is connected. You said in your OP that "but I don't always have three" so you'll have to think about the logic of that with respect to the physical screen layout in those situations.