Skip to content

Instantly share code, notes, and snippets.

@Grayson
Created August 18, 2011 14:03
Show Gist options
  • Save Grayson/1154126 to your computer and use it in GitHub Desktop.
Save Grayson/1154126 to your computer and use it in GitHub Desktop.
Applescript snippet to test if Option key is held down.
on isOptionKeyPressed()
return (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSAlternateKeyMask > 1'") is "True"
end isOptionKeyPressed
@alin89c
Copy link

alin89c commented Sep 22, 2021

I use very often lines that start with do shell script in my scripts. Unfortunately, the script won't compile if it contains the use framweork "Cocoa" line. Is there anything I can do about it? I've read that I need to use an NSTask object instead, but I can't figure out the mechanics of it.

This is the code that doesn't work.

use framework "Cocoa"
do shell script "eval $(/usr/libexec/path_helper -s); sendmidi dev SessionKiano ch 2 on 109 127"

Thank you.

EDIT:
I've found the solution:
According to this, I just needed to add below "use framework..." another line: use scripting additions.
Hurray!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment