Created
August 30, 2017 10:29
-
-
Save anonymous/39cacbf5c3fb7b19889c28b8b033ecb9 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
<?xml version="1.0"?> | |
<root> | |
<item> | |
<name>My Key 52: Minimize All Windows But...</name> | |
<item> | |
<name>...But Active Window_Hold F</name> | |
<identifier>Minimize All Windows But Active Window_Hold F</identifier> | |
<autogen> | |
--HoldingKeyToKey-- | |
KeyCode::F,ModifierFlag::NONE, | |
@begin | |
KeyCode::F, | |
@end | |
@begin | |
KeyCode::F,ModifierFlag::OPTION_L,ModifierFlag::COMMAND_L,ModifierFlag::SHIFT_L,ModifierFlag::CONTROL_L, | |
@end | |
Option::NOREPEAT, | |
</autogen> | |
</item> | |
<item> | |
<name>...But Open Windows of Active App_Hold A</name> | |
<identifier>Minimize All Windows But Open Windows of Active App_Hold A</identifier> | |
<autogen> | |
--HoldingKeyToKey-- | |
KeyCode::A,ModifierFlag::NONE, | |
@begin | |
KeyCode::A, | |
@end | |
@begin | |
KeyCode::A,ModifierFlag::OPTION_L,ModifierFlag::COMMAND_L,ModifierFlag::SHIFT_L,ModifierFlag::CONTROL_L, | |
@end | |
Option::NOREPEAT, | |
</autogen> | |
</item> | |
</item> | |
</root> | |
<!-- Script-Minimize All Windows But Active Window: | |
tell application "System Events" | |
display notification "Release your finger" with title "my key 52" | |
delay 0.5 | |
set openApps to (get name of every application process whose visible is true) | |
set activeApp to (get name of first process where it is frontmost) | |
set targetApps_1 to {} | |
repeat with i from 1 to count openApps | |
if {openApps's item i} is not in activeApp then | |
set targetApps_1's end to openApps's item i | |
end if | |
end repeat | |
delay 0.2 | |
set otherApps to {"Firefox", "VLC", "VideoSpec"} -- (Command + Option + M is not for minimizing all windows) | |
set otherApps_2 to {"Dictionary", "fSync", "Karabiner Preferences"} -- (Can’t get name of window 1,window doesn’t understand the “count” message) | |
set targetApps_2 to {} | |
repeat with i from 1 to count targetApps_1 | |
if {targetApps_1's item i} is not in otherApps then | |
set targetApps_2's end to targetApps_1's item i | |
end if | |
end repeat | |
end tell | |
delay 0.2 | |
set tabApps to {"Firefox", "Google Chrome", "Safari"} | |
if activeApp is not in tabApps then | |
if activeApp is not in otherApps then | |
delay 0.2 | |
if activeApp is not in otherApps_2 then | |
delay 0.2 | |
tell application activeApp | |
activate | |
set activeWindow to (get name of front window) | |
if (count of window) is greater than 1 then | |
delay 0.2 | |
tell application "System Events" | |
keystroke "m" using {command down, option down} | |
end tell | |
end if | |
end tell | |
end if | |
end if | |
end if | |
delay 0.2 | |
-- if (tabApp = activeApp, count menu item) | |
if activeApp is "Safari" then | |
tell application activeApp | |
activate | |
delay 0.2 | |
set activeWindow to (get name of front window) | |
tell application "System Events" | |
tell process activeApp | |
if (count menu item of menu 1 of menu bar item "Window" of menu bar 1) > 14 then | |
delay 0.3 | |
keystroke "m" using {command down, option down} | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
if activeApp is "Google Chrome" then | |
tell application activeApp | |
activate | |
delay 0.2 | |
set activeWindow to (get name of front window) | |
tell application "System Events" | |
tell process activeApp | |
if (count menu item of menu 1 of menu bar item "Window" of menu bar 1) > 19 then | |
delay 0.3 | |
keystroke "m" using {command down, option down} | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
if activeApp is "Firefox" then | |
tell application activeApp | |
activate | |
delay 0.2 | |
set activeWindow to (get name of front window) | |
tell application "System Events" | |
tell process activeApp | |
set menuitemCount to (count menu item of menu 1 of menu bar item "Window" of menu bar 1) | |
delay 0.3 | |
if menuitemCount > 4 then | |
repeat (menuitemCount - 3) times | |
delay 0.6 | |
keystroke "m" using command down | |
end repeat | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
-- end of if (tabApp = activeApp, count menu item) | |
delay 0.2 | |
if activeApp is not "Safari" then | |
tell application activeApp | |
activate | |
delay 0.2 | |
tell application "System Events" | |
tell process activeApp | |
if menu item activeWindow of menu 1 of menu bar item "Window" of menu bar 1 exists then | |
delay 0.5 | |
click menu item activeWindow of menu 1 of menu bar item "Window" of menu bar 1 | |
end if | |
end tell | |
end tell | |
end tell | |
else | |
tell application activeApp | |
activate | |
delay 0.2 | |
if length of activeWindow is greater than 28 then | |
set activeWindow_2 to text 1 thru 28 of activeWindow | |
delay 0.2 | |
tell application "System Events" | |
tell process "Safari" | |
click (menu item 1 where its name starts with activeWindow_2) of menu 1 of menu bar item "Window" of menu bar 1 | |
end tell | |
end tell | |
else | |
tell application "System Events" | |
tell process activeApp | |
if menu item activeWindow of menu 1 of menu bar item "Window" of menu bar 1 exists then | |
delay 0.5 | |
click menu item activeWindow of menu 1 of menu bar item "Window" of menu bar 1 | |
end if | |
end tell | |
end tell | |
end if | |
end tell | |
end if | |
delay 0.4 | |
repeat with targetApp in targetApps_2 | |
delay 0.1 | |
tell application targetApp | |
activate | |
delay 0.2 | |
tell application "System Events" | |
keystroke "m" using {command down, option down} | |
end tell | |
end tell | |
end repeat | |
delay 0.2 | |
-- Minimize 'otherApps' windows | |
if (item 1 of otherApps) is in openApps then -- item 1 of otherApps | |
if (item 1 of otherApps) is not in activeApp then | |
tell application "Firefox" | |
activate | |
delay 0.3 | |
tell application "System Events" | |
tell process "Firefox" | |
set menuitemCount to (count menu item of menu 1 of menu bar item "Window" of menu bar 1) | |
delay 0.2 | |
if menuitemCount > 3 then | |
repeat (menuitemCount - 3) times | |
delay 0.7 | |
keystroke "m" using command down | |
end repeat | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
end if | |
delay 0.2 | |
if (item 2 of otherApps) is in openApps then -- item 2 of otherApps | |
if (item 2 of otherApps) is not in activeApp then | |
tell application "VLC" | |
activate | |
delay 0.2 | |
tell application "System Events" | |
tell process "VLC" | |
if menu item "Minimize All" of menu 1 of menu bar item "Window" of menu bar 1 exists then | |
delay 0.2 | |
click menu item "Minimize All" of menu 1 of menu bar item "Window" of menu bar 1 | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
end if | |
delay 0.2 | |
if (item 3 of otherApps) is in openApps then -- item 3 of otherApps | |
if (item 3 of otherApps) is not in activeApp then | |
tell application "VideoSpec" | |
activate | |
delay 0.2 | |
tell application "System Events" | |
keystroke "m" using command down | |
end tell | |
end tell | |
end if | |
end if | |
delay 0.2 | |
tell application activeApp | |
activate | |
end tell | |
-- END of Script-Minimize All Windows But Active Window | |
Script-Minimize All Windows But Open Windows of Active App: | |
tell application "System Events" | |
display notification "Release your finger" with title "my key 52" | |
delay 0.2 | |
set openApps to (get name of every application process whose visible is true) | |
set activeApp to (get name of first process where it is frontmost) | |
set targetApps_1 to {} | |
repeat with i from 1 to count openApps | |
if {openApps's item i} is not in activeApp then | |
set targetApps_1's end to openApps's item i | |
end if | |
end repeat | |
delay 0.2 | |
set otherApps to {"Firefox", "VLC", "VideoSpec"} -- (Command + Option + M is not for minimizing all windows) | |
set targetApps_2 to {} | |
repeat with i from 1 to count targetApps_1 | |
if {targetApps_1's item i} is not in otherApps then | |
set targetApps_2's end to targetApps_1's item i | |
end if | |
end repeat | |
end tell | |
repeat with targetApp in targetApps_2 | |
delay 0.3 | |
tell application targetApp | |
activate | |
delay 0.2 | |
tell application "System Events" | |
keystroke "m" using {command down, option down} | |
end tell | |
end tell | |
end repeat | |
delay 0.2 | |
-- Minimize 'otherApps' windows | |
if (item 1 of otherApps) is in openApps then -- item 1 of otherApps | |
if (item 1 of otherApps) is not in activeApp then | |
tell application "Firefox" | |
activate | |
delay 0.3 | |
tell application "System Events" | |
tell process "Firefox" | |
set menuitemCount to (count menu item of menu 1 of menu bar item "Window" of menu bar 1) | |
delay 0.2 | |
if menuitemCount > 3 then | |
repeat (menuitemCount - 3) times | |
delay 0.7 | |
keystroke "m" using command down | |
end repeat | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
end if | |
delay 0.2 | |
if (item 2 of otherApps) is in openApps then -- item 2 of otherApps | |
if (item 2 of otherApps) is not in activeApp then | |
tell application "VLC" | |
activate | |
delay 0.2 | |
tell application "System Events" | |
tell process "VLC" | |
if menu item "Minimize All" of menu 1 of menu bar item "Window" of menu bar 1 exists then | |
delay 0.2 | |
click menu item "Minimize All" of menu 1 of menu bar item "Window" of menu bar 1 | |
end if | |
end tell | |
end tell | |
end tell | |
end if | |
end if | |
delay 0.2 | |
if (item 3 of otherApps) is in openApps then -- item 3 of otherApps | |
if (item 3 of otherApps) is not in activeApp then | |
tell application "VideoSpec" | |
activate | |
delay 0.2 | |
tell application "System Events" | |
keystroke "m" using command down | |
end tell | |
end tell | |
end if | |
end if | |
delay 0.2 | |
tell application activeApp | |
activate | |
end tell | |
-- END of Script-Minimize All Windows But Open Windows of Active App | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment