Running Shortcuts with keyboard modifiers

I wanted my cascade windows shortcut to have options. Originally I just wanted to rearrange all windows of the focused app. To do that for all apps or choosing whether or not to resize the windows, I could show a menu or have multiple shortcuts.

Instead, I found a way for shortcuts to check whether a modifier key is held down when run:


(note: I’ve named the variable and set type to boolean in the ‘If’ action)

// Return true if SHIFT is pressed
function run(input, parameters) {
	ObjC.import("Cocoa")
	if ($.NSEvent.modifierFlags & $.NSEventModifierFlagShift) {
		return true
	}
}

There’s also flags for Control, Option, Command etc. Hope it’s useful!