Hi.. I'm making a menu bar application and I'm trying to get the currently selected text.
This is my code so far:
The problem with this is that the menu bar app has no windows open, and therefore says there is no object at index 0 when that code is run. Instead of getting the orderedWindows array from NSApp (which is the menu bar app itself), where can I get the array for the windows open on the entire system?
This is my code so far:
Code:
NSString *string;
NSWindow *frontWindow = [[NSApp orderedWindows] objectAtIndex:0];
id firstResponder = [frontWindow firstResponder];
if ([firstResponder isKindOfClass:[NSText class]])
{
if ([firstResponder selectedRange].length == 0)
{
return;
}
else
{
string = [[firstResponder string] substringWithRange:[firstResponder selectedRange]];
}
}
The problem with this is that the menu bar app has no windows open, and therefore says there is no object at index 0 when that code is run. Instead of getting the orderedWindows array from NSApp (which is the menu bar app itself), where can I get the array for the windows open on the entire system?