gpt4 book ai didi

MacOS : get foremost window title

转载 作者:行者123 更新时间:2023-12-03 02:11:21 26 4
gpt4 key购买 nike

我使用此代码来获取窗口标题:

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 ,它因错误而失败。它也不适用于预览版。

无论如何,即使对于像 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}

Getting the currently open file and path from Preview 得到这个想法.

关于MacOS : get foremost window title,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5292204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com