Skip to content

Instantly share code, notes, and snippets.

@timpulver
Created February 11, 2013 10:38
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save timpulver/4753750 to your computer and use it in GitHub Desktop.
Save timpulver/4753750 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
@joereddington
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment