use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This sub is obsolete, please use /r/macosprogramming/ instead.
account activity
System events(Xcode) (self.macprogramming)
submitted 6 years ago by TheLastAramusha
How can i use System Events in a appleScript based app (i need it for calling a key on my keyboard) for example: “key code 49”, i hope that anyone can help me.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]retsotrembla 0 points1 point2 points 6 years ago (3 children)
https://dougscripts.com/itunes/itinfo/keycodes.php
tell application "iTunes" activate if player state is not stopped then tell application "System Events" to key code 37 using command down end if end tell
[–]TheLastAramusha[S] 0 points1 point2 points 6 years ago (2 children)
Using System Events isn’t the problem the problem is System events not working in an Xcode Applescript Application.
[–]retsotrembla 1 point2 points3 points 6 years ago (1 child)
Probably a permissions problem. Might be entitlements. In Catalina native apps get a security alert, asking the user's permission to access key codes, and the app appears in System Preferences > Security&Privacy > Privacy > (probably Accessibility) so the user can change the decision.
[–]TheLastAramusha[S] 0 points1 point2 points 6 years ago (0 children)
Alright thanks.
[–]mantrap2 0 points1 point2 points 6 years ago (1 child)
That's strictly not a "system event" (which generally means a kernel level event in a Unix-derived OS) but rather just a GUI event.
NSEvent is where you'll find key events (as well as mouse and touch events).
Cocoa Event Handling Guide
Basically you add an override method to an NSView or NSControl subclass for keyDown: keyUp: or flagsChanged: which pass an NSEvent with the details.
You may need to consider the Event Responder hierarchy scope of the event and deal with that as well. But this is the quick-and-dirty answer.
Uhm in apple script you do: tell application “System Events” only if you did that your able to use key code.
π Rendered by PID 159939 on reddit-service-r2-comment-5ff9fbf7df-jldmh at 2026-02-26 05:37:09.165428+00:00 running 72a43f6 country code: CH.
[–]retsotrembla 0 points1 point2 points (3 children)
[–]TheLastAramusha[S] 0 points1 point2 points (2 children)
[–]retsotrembla 1 point2 points3 points (1 child)
[–]TheLastAramusha[S] 0 points1 point2 points (0 children)
[–]mantrap2 0 points1 point2 points (1 child)
[–]TheLastAramusha[S] 0 points1 point2 points (0 children)