CollapseTo hotkey? (how to use selected modifier's index number?)

Sorry in advance, I'm new to scripting and all I know is how to do basic macros.

Here's an image demonstrating 2 separate situations illustrating my problem.
If I want to use maxOps.CollapsNodeTo $ (number) off, I need to replace (number) with an updated value depending on the selected modifier's index number.