Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixpetrov/ebe0a61617926cf144131b28bf87d0c8 to your computer and use it in GitHub Desktop.
Save sixpetrov/ebe0a61617926cf144131b28bf87d0c8 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