Reputation: 5169
I want my console to beep when a task finishes in a terminal I'm not watching.
I actually have it all worked out in Linux:
function beeper_preexec {
focus_window=`xdotool getwindowfocus`
}
function beeper_precmd {
retval=$?
if [[ $focus_window -ne `xdotool getwindowfocus` ]]; then
if [[ $retval -ne 0 ]]; then
beep -f 329.6
else
beep
fi
fi
}
function beeper_setup {
add-zsh-hook precmd beeper_precmd
add-zsh-hook preexec beeper_preexec
}
Does anyone know something I can use to replace xdotool getwindowfocus
on OS X? I don't particularly care if it returns the PID or window id, it just needs to change when the focused window switches.
Upvotes: 1
Views: 2440
Reputation: 3069
I'm not exactly sure how I would approach this, but I did a small amount of research and it seems that you can use AppleScript to get the current window title and then compare that to the expected window title of Terminal.
From: MacOSX: get foremost window title
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}
Upvotes: 2