参考之前询问的question,我想知道如何获取当前活动文档的标题。
我试过在回答上述问题时提到的剧本。这是可行的,但只提供了应用程序的名称。例如,我在写这个问题:当我启动脚本时,它会给我应用程序的名称,即“Firefox”。这是相当整洁,但没有真正的帮助。我希望捕获当前活动文档的标题。看图片。
Firefox title http://img.skitch.com/20090126-nq2egknhjr928d1s74i9xixckf.jpg
我使用的是Leopard,所以不需要向后兼容。另外,我使用Python的Appkit来访问NSWorkspace类,但是如果您告诉我Objective-C代码,我可以找到Python的转换。
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调用它。
在Objective-C中,简单的答案是,使用一点可可粉,主要是Carbon Accessibility API:
或者,如this StackOverflow answer中所述,使用CGWindow API可能更简单。
据我所知,你最好的办法是包装一个AppleScript。但AppleScript对我来说很神奇,所以我把它留给提问者练习:-)
这可能有点帮助:A script to resize frontmost two windows to fill screen - Mac OS X Hints
相关问题 更多 >
编程相关推荐