Is it possible to trigger a script differently when the Option key is held while the script is run?
I would love to be able to run a script on the selected master OR all masters.
EDIT :
This code seems to work :
import AppKit
import Quartz
def check_option_key():
# Get the current event flags (key states)
flags = Quartz.CGEventSourceFlagsState(Quartz.kCGEventSourceStateHIDSystemState)
# Check if the Option key (Alt key) is pressed
if flags & Quartz.kCGEventFlagMaskAlternate:
print("Option (Alt) key is pressed")
else:
print("Option (Alt) key is not pressed")
if __name__ == "__main__":
check_option_key()
So now my question is, it is possible to update name displayed in Menu while Option key is pressed ?
The title of menu items does not change when the Option key is held down. Instead, the menu contains two menu items next to each other, the second of which has alternate set to True. Holding down the modifier key that differentiates the two menu items automatically hides the first item and reveals the second. For scripts, there is currently no automatic way to set this property for their generated menu items.
Thanks for this info Florian.
Do you think it would be technically possible to implement it ?
I, and I guess many others, have scripts that could be triggered for the selected master or all masters. Currently, the only solution is to duplicate and modify the script. (Or use the method I mentioned before, but it makes it really hard to tell other users about this feature.)
You could move the core of the code into a separate file and then import that file from the two scripts. See this example where ToggleSelectSegment.py is reused by the Up/Down/Left/Right scripts: