All pastes #445631 Raw Edit

Something

public text v1 · immutable
·published 2007-04-17 23:55 UTC
rendered paste body
delay 2
-- Get Path to frontmost application
set appl to path to frontmost application as string

-- Get app's name
-- Known bugs:
-- #1: 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: 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. (Also, it's possibly because these aren't browser windows, and their (view) has different stuff or they don't have a view)
	
	tell application "iTunes"
		set windowtitle to "ITS_OR_IPG" -- bugfix (#1)
		if visuals enabled then
			set windowtitle to name of current visual
		else
			try
				set windowtitle to name of view of frontw
			on error
				try
					set windowtitle to special kind of view of front window
				on error
					set windowtitle to "iTunes"
				end try
			end try
		end if
		
		if windowtitle is "ITS_OR_IPG" then -- bugfix (#1 cont'd)
			if window 1 is EQ window 1 then
				set windowtitle to "Equalizer"
			else
				set windowtitle to "iTunes"
			end if
		end if
		
	end tell
else if appname is "Quicksilver" then
	try
		tell application appl
			set windowtitle to name of front window
		end tell
	on error
		set windowtitle to appname
	end try
else
	tell application appl
		set windowtitle to name of front window
	end tell
end if

if windowtitle is appname then
	return "I am looking at " & appname & "." as string
else
	return "I am looking at " & "\"" & windowtitle & "\"" & " in " & appname & "." as string
end if