Friday, February 22, 2019

#1 2018-10-16 04:31:05 pm

From:: Retondo
Registered: 2016-08-27
Posts: 4

How to get the firstResponder object of Xcode 10 window.

How can I get the firstResponder object of the current Xcode 10 window? I need to know if the keyboard focus is set to the Source Editor or any other object. I have a SourceEditorExtension and I'm trying to get around a bug in Xcode. Xcode enables a SourceEditorExtension even if the focus in NOT in the Source Editor. My extension shouldn't be called say if the focus is in the Find edit box. I can prevent my extension from running if the focus in NOT in the Source Editor.

Ok, I've learned just enough AppleScriptObjC to make me dangerous. I found out that a NSWindow has a firstResponder property. So I want to get the current application and ask it for it's front window. Then I can ask the window for it's firstResponder. But I can't figure out how to get the front NSWindow. Here's what I've got so far which isn't working. Any ideas would be great.

property NSWorkspace : a reference to current application's NSWorkspace
property NSApplication : a reference to current application's NSApplication
property sharedWorkspace : a reference to NSWorkspace's sharedWorkspace
property NSWindow : class "NSWindow" of current application

set runningApplications to sharedWorkspace()'s runningApplications()
set frontApp to NSApplication's sharedApplication()
set frontWindow to NSWindow's front window  -- NOT WORKING
set theFirstResponder to frontWindow's firstResponder

Last edited by mretondo (2018-10-19 05:22:09 pm)



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)