Active Window Title

Discussion in 'Mac Programming' started by ruhi, Jul 14, 2009.

  1. macrumors member

    Joined:
    Jun 17, 2009
    #1
    hello, i want to get the title of the active application's window...Please help me how can i get that?? :confused:

    Thanks in advance.
     
  2. macrumors regular

    Joined:
    May 27, 2009
    Location:
    Glasgow, Scotland
    #2
    I would advise you to have a look at NSWindow in the documentation.

    (Managing Titles section)

    Stephen
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    You didn't say what you were using or what the purpose is. It sounds like you might want AppleScript (if the mystery window is not your app)?
     
  4. thread starter macrumors member

    Joined:
    Jun 17, 2009
    #4
    active window title

    i don't find any help in managing titles as i dont know which is the active application.

    i can find the active application name with some other information my [[NSWorkspace sharedworkspace] activeapplication]; but i am not able to get the title of this active application's window.
     
  5. thread starter macrumors member

    Joined:
    Jun 17, 2009
    #5
    active window title

    i am not looking for my application if its active, i want it if any other application other than my own application is active i want its window title.

    Please help me!
     
  6. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #6
    Here's an AppleScript I found that will do the job:

    Code:
    tell application "System Events"
    	set frontApp to name of first application process whose frontmost is true
    end tell
    tell application frontApp
    	if the (count of windows) is not 0 then
    		set window_name to name of front window
    	end if
    end tell
    You can call AppleScript from Cocoa using NSAppleScript, or you can do an NSTask and call it from the command-line using the osascript command. See this article for details. There might be a way to do it directly from Cocoa but I'm guessing AppleScript is going to be your best bet here.
     
  7. thread starter macrumors member

    Joined:
    Jun 17, 2009
    #7
    Thanks

    Hey Thanks it worked..Thanx:)
     
  8. thread starter macrumors member

    Joined:
    Jun 17, 2009
    #8
    Active window title

    I am facing few problems with this apple script now.

    Like when i open firefox, it shows a window "Where is Firefox-bin?"

    why is this coming??
    I think i need to do this by cocoa.

    Please suugest me some way.
    Thanks,
    Ruhi.
     

Share This Page