Created
September 15, 2016 06:36
-
-
Save bhavyaw/af4bb47d6680bc70e8f143d5170c4893 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set windowTitle to "" | |
set currentTabTitle to "" | |
set appID to "" | |
set appName to "" | |
set comments to "" | |
set wins to "" | |
set anyFinderWindowVisible to false | |
set anyVisibleWindow to anyVisibleWindow() | |
tell application "System Events" | |
set frontApp to first application process whose frontmost is true | |
set appName to name of frontApp | |
set appID to unix id of frontApp | |
tell frontApp | |
try | |
tell (1st window whose value of attribute "AXMain" is true) | |
set windowTitle to value of attribute "AXTitle" | |
set appName to name of frontApp | |
set appID to unix id of frontApp | |
end tell | |
on error | |
if exists ( 1st window of frontApp ) then | |
set firstWindow to 1st window | |
tell (firstWindow whose value of attribute "miniaturized" is true) | |
if anyVisibleWindow is true then | |
set visible of frontApp to false | |
else | |
set appID to -1 | |
set appName to "" | |
set windowTitle to "" | |
end if | |
end tell | |
else | |
-- app closed case | |
if anyVisibleWindow is true then | |
set visible of frontApp to false | |
else | |
set appID to -1 | |
set appName to "" | |
set windowTitle to "" | |
end if | |
end if | |
end try | |
end tell | |
end tell | |
return {comments,wins,windowTitle,appName,appID} | |
on anyVisibleWindow() | |
set visibleWindowIds to {} | |
set message to "" | |
tell application "System Events" | |
set listOfProcesses to (name of every process where background only is false) | |
end tell | |
repeat with visibleProcess in listOfProcesses | |
try | |
tell application visibleProcess to set visibleWindowIds to visibleWindowIds & (id of windows whose visible is true) | |
on error someError | |
set message to message & "Some error occurred: " & someError & "; " | |
end try | |
end repeat | |
return visibleWindowIds is not {} | |
end anyVisibleWindow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment