Applescript to Toggle Floating/Unfloating Window

I created a keyboard shortcut (keypad “5” plus command, option, control) to toggle floating of the Drafts window (since Drafts doesn’t offer one). It works, but only while in-app, of course, and frustration with the floating window comes when you’re NOT in the app. So I’m creating an applescript to invoke the shortcut from anywhere. And it’s not working.

This is obviously a scripting question, not a Drafts question (again, the shortcut itself does work), but I’m hoping maybe someone can help. I realize there are other ways to accomplish this, but I’m mystified as to what I’ve done wrong here.

FWIW, here are all the Applescript Key Codes

tell application "System Events"
	tell application "Drafts" to activate

	tell application "System Events" to keystroke "key code 87" using {command down, option down, control down}
end tell

Try this.

tell application "Drafts" to activate
tell application "System Events" to key code 87 using {command down, option down, control down}
1 Like

Perfect. Thanks very much, sylumer.

Yep, key code vs keystroke (inconsistent spacing and all) can be confusing.

BTW, to my fellow brainless idiots: don’t set the same keystroke to launch the script as the keystroke used in the script (remember when Captain Kirk destroyed the computer by asking it to compute the entirety of pi?)

Also: life is better with this shortcut. Floating windows are one of those smart conveniences that can really aggravate you when they seem to work against you (I’m not complaining, Greg!). Also, this has the added benefit of bringing the unfloated Draft window back in view (once it’s behind lots of windows).

1 Like