-- What's Front.scpt
-- A script by William Donaldson
-- This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
-- Use: Tells you the program and title of the window you're currently active in.
-- Thanks to: "Peter Anderson2" for helping solve the iTunes "iPod Games" and iTunes store bug
-- delay 2 -- if testing in script editor, uncomment this line so it waits two seconds before getting info
-- Get Path to frontmost application
set appl to path to frontmost application as string
-- Get app's name
-- Known bugs:
-- #1 (FIXED): Quicksilver does not work with this. (FIXED)
try
tell application appl
set appname to name
end tell
on error
-- Programs that don't correctly report their name
if appl contains "Quicksilver" then -- bugfix (#1)
set appname to "Quicksilver"
end if
end try
--Other Program support
if appname is "iTunes" then
-- iTunes Support
-- Known supported versions: 7.1.1 (5)
-- Known bugs:
-- #1 (FIXED): When looking at 'iPod Games' or the iTunes Store, these don't return special kinds or valid names (returns the value of windowtitle last time it ran somehow?!?), so I've set it to set iTunes as default. This appears to be a bug in iTunes, as there seems to be no other way to get this information through AppleScripting. (FIXED: Through use of System Events)
tell application "iTunes"
if visuals enabled then
set windowtitle to name of current visual
else if name of front window is not "iTunes" then
set windowtitle to name of front window
else
try
set windowtitle to name of view of front window
on error -- If they don't have a name, they'll likely have a special kind.
try
set windowtitle to special kind of view of front window
on error -- If not, we need to determine what it is by other means! (Bugfix #1)
if window 1 is EQ window 1 then -- Equalizer
set windowtitle to "Equalizer"
else
try
tell application "System Events"
tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1 of process "iTunes"
-- if anyone knows of a more efficient way to do the following 7 lines, please let me know. thanks!
set n to 1
repeat until value of attribute "AXSelected" of row n is true
set n to n + 1
end repeat
tell row n
set windowtitle to value of attribute "AXValue" of static text 1
end tell
end tell
end tell
on error -- Too lazy to tell people to enable UI Scripting.
set windowtitle to "iTunes" -- always need a fallback plan just in case!
end try
end if
end try
end try
end if
end tell
else
try
tell application appl
set windowtitle to name of front window
end tell
on error
set windowtitle to appname
end try
end if
if windowtitle is appname then -- If a program just returns the app name as a window title, don't even bother displaying it.
return "I am looking at " & appname & "." as string
else
return "I am looking at " & "\"" & windowtitle & "\"" & " in " & appname & "." as string
end if