Using Keyboard Maestro to detect the end of the timeline in Pro Tools?

This may seem a pedantic point, but I hope it might help bring clarity. The question is not how Keyboard Maestro will recognise that there are no more clips, but how your macro will. In other words, you need to (1) work out the logic of the sequence of events needed and (2) implement that in your macro. These are related but distinct challenges.

For (1), @Larry_Mah suggests an imaginative approach. You could consider that as well as any other ideas that occur.

For (2), you will need to know how to arrange actions in your macro to produce the desired result.

Current users of Pro Tools can help you with (1). There are far more people here who will be able to help you with (2), but you will need to ask specific questions to get specific answers.