我想要一个脚本来显示和隐藏带有特定文件的 VIM 窗口和键盘快捷键(将通过 BetterTouchTool 完成)。我的脚本中的所有内容都可以正常工作,希望隐藏窗口。
我试图找到 AXRaise
的反面,但没有找到关于此的一些文档。
if application "MacVim" is running then
log "macvim running"
tell application "System Events"
log "tell app system events"
tell application process "MacVim"
log "- tell app process macvim"
if exists (first window whose name contains "journal") then
log "-- window contains journal"
# @todo have to toggle between visible and not visible
if (get frontmost) then
log "true: " & (get frontmost)
# How to hide the window ??
else
log "false: " & (get frontmost)
# set visible to true
# set frontmost to true
perform action "AXRaise" of (first window whose name contains "journal")
end if
else
log "- no window with journal"
do shell script "/Users/foobar/bin/jo > /dev/null 2>&1 &"
end if
end tell
end tell
else
log "no macvim running"
do shell script "/Users/foobar/bin/jo > /dev/null 2>&1 &"
end if
答案 0 :(得分:1)
在basic vanilla AppleScript的上下文中,应用程序的窗口有两种方式隐藏。
miniaturizable
property 是 true
,将其 miniaturized
property 设置为:true
visible
property 设置为:false
visible
property 设置为 false
时,它不再出现在下面显示的打开窗口列表中其 UI 中的 窗口 菜单,并将保持这种状态,直到它重置为 true
,而应用程序 仍在运行。 示例 AppleScript 代码:
通过最小化隐藏:
tell application "MacVim" to ¬
set miniaturized of ¬
(first window whose name contains "journal") to true
在 miniaturized
设置为:true
tell application "MacVim" to ¬
set miniaturized of ¬
(first window whose name contains "journal") to false
或者:
tell application "MacVim" to ¬
set visible of ¬
(first window whose name contains "journal") to true
要隐藏,将 visible
设置为:false
tell application "MacVim" to ¬
set visible of ¬
(first window whose name contains "journal") to false
要取消隐藏,将 visible
设置为:true
tell application "MacVim" to ¬
set visible of ¬
(first window whose name contains "journal") to true
tell application "System Events" to ¬
tell application "MacVim" to ¬
set miniaturized of ¬
(first window whose name contains "journal") to true
注意:示例 AppleScript 代码就是这样,没有任何包含的错误处理不包含任何额外的错误处理。用户有责任根据需要添加任何错误处理。查看 try 中的 error statement 和 AppleScript Language Guide statement。另见Working with Errors。此外,在适当的情况下,可能需要在事件之间使用 delay command,例如delay 0.5
,适当设置 delay 的 value。