Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the title of the current active Window/Document in Mac OS X

Tags:

Refering to a previously asked question, I would like to know how to get the title of the current active document.

I tried the script mention in the answers to the question above. This works, but only gives me the name of the application. For example, I am writing this question: When I fire up the script it gives me the name of the application, i.e. "Firefox". This is pretty neat, but does not really help. I would rather like to capture the title of my current active document. See the image.

Firefox title http://img.skitch.com/20090126-nq2egknhjr928d1s74i9xixckf.jpg

I am using Leopard, so no backward compatibility needed. Also I am using Python's Appkit to gain access to the NSWorkspace class, but if you tell me the Objective-C code, I could figure out the translation to Python.


Ok, I've got a solution which is not very satisfing, thats why I don't mark Koen Bok's answer. At least not yet.
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

Save as script and invoke it with osascript from the shell.

like image 897
sebastiangeiger Avatar asked Jan 26 '09 18:01

sebastiangeiger


People also ask

How to Move open windows on Mac?

Move a window to one side of the screen: Press and hold the Option key while you move the pointer over the green button in the top-left corner of the window, then choose Move Window to Left Side of Screen or Move Window to Right Side of Screen from the menu that appears.


1 Answers

As far as I know your best bet is wrapping an AppleScript. But AppleScript is magic to me so I leave it as an exercise for the questioner :-)

This might help a little: A script to resize frontmost two windows to fill screen - Mac OS X Hints

like image 102
Koen Bok Avatar answered Oct 02 '22 20:10

Koen Bok