我正在尝试以编程方式检索 aquamacs 的主要模式。我有一些想法:获取菜单栏项目,获取窗口标题并使用正则表达式解析它。
我都试过了,但遇到了一个问题,菜单栏和窗口数组都是空的,这使得不可能做到这一点:
on test()
try
tell application "System Events"
if application "Aquamacs" exists then
-- display notification "It's aquamacs"
tell application "Aquamacs" to activate
if menu bar item "File" of menu bar 1 exists then
display notification "File exists"
--Fails when the file menu bar item clearly is there
else
display notification "File doesn't exist"
end if
else
display notification "It isn't aquamacs"
end if
end tell
end try
end test
test()
或这个:
on getAppTitle(appN)
tell application appN
activate
end tell
tell application "System Events"
# Get the frontmost app's *process* object.
set frontAppProcess to first application process whose frontmost is true
end tell
# Tell the *process* to count its windows and return its front window's name.
tell frontAppProcess
if (count of windows) > 0 then --never runs because count is always zero
set window_name to name of every window
end if
end tell
end getAppTitle
getAppTitle("Aquamacs")
然后查看文件扩展名。
我不明白为什么系统和 AppleScript 之间存在这种不一致:它显然有窗口,这些窗口肯定有标题,但不知何故超出了脚本的范围。