Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mals14/b4dea89d330bcafaba49ff8c97689552 to your computer and use it in GitHub Desktop.
Save mals14/b4dea89d330bcafaba49ff8c97689552 to your computer and use it in GitHub Desktop.
[AppleScript] Get Name of active window | Returns the name / title of the active (frontmost) window
# taken from user Albert's answer on StackOverflow
# http://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title
# 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}
#!/bin/bash
for i in `seq 1 5`;
do
echo $i
echo `osascript GetNameAndTitleOfActiveWindow.scpt`
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment