MacOSX的:最重要的获取窗口标题 [英] MacOSX: get foremost window title
本文介绍了MacOSX的:最重要的获取窗口标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这code拿到窗口标题:
I am using this code to get the window title:
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
tell application frontApp
set window_name to name of front window
end tell
然而,该失败在某些情况下。显然,在没有打开的窗口,但是这是确定的失败。然而,在某些情况下,例如用于 Texmaker 时,它失败的错误。它也没有为preVIEW工作。
However, this fails in some cases. Obviously it fails when there is no open window but that is Ok. However, in some cases, for example for Texmaker, it fails with an error. It also doesn't work for Preview.
这将是一个办法让窗口标题,无论如何,即使对于像Texmaker情况?
What would be a way to get the window title anyway, even for cases like Texmaker?
推荐答案
这似乎总是工作:
global frontApp, frontAppName, windowTitle
set windowTitle to ""
tell application "System Events"
set frontApp to first application process whose frontmost is true
set frontAppName to name of frontApp
tell process frontAppName
tell (1st window whose value of attribute "AXMain" is true)
set windowTitle to value of attribute "AXTitle"
end tell
end tell
end tell
return {frontAppName, windowTitle}
得到这里 。
Got the idea from here.
这篇关于MacOSX的:最重要的获取窗口标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文