Can I get the first responder of Xcode? I want to see if the main editor has the focus.
Hey Mike,
I don't use Xcode, so I'm not sure if this is what you're wanting, but...
Try this AppleScript in the Script Editor.app with an edit window frontmost in Xcode. See if it returns true or false.
-Chris
tell application "System Events"
tell application process "Xcode"
tell (first window whose subrole is "AXStandardWindow")
tell splitter group 1
tell group 1
tell splitter group 1
tell group 1
tell group 1
if not (exists of (first menu button whose description is "Related Items")) then
error "Front window is NOT an editing window!"
end if
end tell
tell scroll area 1
tell text area 1
focused
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell
Thanks for the help. Using your code and debugging I came up with code that returns true if either source editor is the "first responder" i.e. has focus.
use AppleScript version "2.4" -- Yosemite (10.10) or later
using terms from application "Xcode"
set workspaceDocument to active workspace document of application "Xcode"
tell application "System Events"
tell application process "Xcode"
set projectName to name of workspaceDocument
set isFocused to false
if not isFocused then
try
-- Assistant Editor has focus with Standard Editor opened
set isFocused to focused of ¬
text area 1 of ¬
scroll area 1 of ¬
group 1 of ¬
splitter group 1 of ¬
splitter group 1 of ¬
splitter group 1 of ¬
group 2 of ¬
splitter group projectName of ¬
window 1
end try
end if
if not isFocused then
try
-- Standard Editor has focus with Assistant Editor closed
set isFocused to focused of ¬
text area 1 of ¬
scroll area 1 of ¬
group 1 of ¬
splitter group 1 of ¬
group 2 of ¬
splitter group projectName of ¬
window 1
end try
end if
if not isFocused then
try
-- Standard Editor has focus with Assistant Editor opened
set isFocused to focused of ¬
text area 1 of ¬
scroll area 1 of ¬
group 1 of ¬
splitter group 1 of ¬
splitter group 1 of ¬
group 2 of ¬
splitter group projectName of ¬
window 1
end try
end if
end tell
return isFocused
end tell
end using terms from