Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[AppleScript] Get Name of active window | Returns the name / title of the active (frontmost) window
# taken from user Albert's answer on StackOverflow
# tested on Mac OS X 10.7.5
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}
for i in `seq 1 5`;
echo $i
echo `osascript GetNameAndTitleOfActiveWindow.scpt`
sleep 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment