X中获取当前活动的窗口

X中获取当前活动的窗口

本文介绍了在Mac OS X中获取当前活动的窗口/文档的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

请参阅先前询问的问题,我想知道如何获取当前活动文档的标题.

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

我尝试了上述问题的答案中提到的脚本.这可行,但仅给我应用程序的名称.例如,我正在写这个问题:启动脚本时,它会给我应用程序的名称,即"Firefox".这很整洁,但并没有真正的帮助.我想捕获当前活动文档的标题.看到图像.

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标题http://img.skitch.com/20090126-nq2egknhjr928d1s74i9xixckf.jpg a>

我正在使用Leopard,因此不需要向后兼容.另外,我正在使用Python的Appkit来访问NSWorkspace类,但是如果您告诉我Objective-C代码,则可以弄清楚对Python的翻译.


好的,我有一个不是很令人满意的解决方案,这就是为什么我没有标注Koen Bok的答案.至少还没有.

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

另存为脚本,并通过shell中的osascript调用它.

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

推荐答案

据我所知,您最好的选择是包装AppleScript.但是AppleScript对我来说是神奇的,因此我将其作为发问者的练习:-)

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 :-)

这可能会有所帮助:用于调整最前面两个窗口的大小以填充屏幕的脚本- Mac OS X提示

这篇关于在Mac OS X中获取当前活动的窗口/文档的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:09