Skip to content

Instantly share code, notes, and snippets.

Created October 10, 2017 00:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/aa673d7b133ca70c9bfbf55c8bff8986 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<root>
<item>
<name>My Key 52.4: 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
<!-- Spark shortcut -->
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
<!-- Spark shortcut -->
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"
-- fixed: Minimize window of OpenOffice.org
-- fixed: if activeApp is "soffice", error: "Can’t get application \"soffice\"." number -1728 from current application
display notification "Release your finger" with title "my key 52.4"
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", "iTunes", "Atom", "soffice"} -- (item 1-4: Command + Option + M is not for minimizing all windows, item 5: Atom Helper got an error: Application isn’t running." number -600)
set otherApps_2 to {"Dictionary", "fSync", "Karabiner Preferences"} -- (Can’t get name of window 1,window doesn’t understand the “count” message)
set otherApps_3 to {"iTunes"} -- set new rules to unminimize active window
set otherApps_4 to {"VLC", "VideoSpec", "soffice"} -- if activeApp is "VLC" or "VideoSpec", script killed. | item 3: "soffice" (OpenOffice.org) error: error "Can’t get application \"soffice\"." number -1728 from current application
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
if activeApp is "soffice" then
tell application "System Events"
set frontmost of process "soffice" to true
delay 0.2
tell process "soffice"
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
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 if
end tell
end tell
end if
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 or activeApp is not in otherApps_4 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 activeApp is "iTunes" then
tell application "iTunes"
activate
delay 0.2
set activeWin to (get name of front window)
set iTunesWin_1 to {"Multiple Song Info", "Song Info"} -- cancel window
if activeWin is in iTunesWin_1 then
tell application "System Events"
key code 53
end tell
end if
delay 0.2
set iTunesWin_2 to (get name of every window)
if "MiniPlayer" is in iTunesWin_2 then -- minimize window
delay 0.7
if "iTunes" is name of front window then
tell application "System Events"
keystroke "m" using command down
end tell
else
tell application "System Events"
tell process "iTunes"
delay 0.2
click menu item "iTunes" of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 0.9
tell application "System Events"
delay 0.4
keystroke "m" using command down
delay 0.4
end tell
end if
set winCount to (count window)
if winCount is greater than 2 then -- windows: Activity,Equalizer
if "Activity" is in iTunesWin_2 then
tell application "System Events"
tell process "iTunes"
if menu item "Activity" of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.2
click menu item "Activity" of menu 1 of menu bar item "Window" of menu bar 1
end if
end tell
delay 0.2
keystroke "m" using command down
end tell
end if
if "Equalizer" is in iTunesWin_2 then
delay 0.3
if "Equalizer" is name of front window then
delay 0.4
tell application "System Events"
keystroke "m" using command down
delay 0.4
end tell
else
tell application "System Events"
tell process "iTunes"
delay 0.2
click menu item "Equalizer" of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 0.9
tell application "System Events"
delay 0.4
keystroke "m" using command down
delay 0.4
end tell
end if
end if
end if
else -- "MiniPlayer" is NOT in iTunesWin_2
set winCount to (count window)
repeat winCount times
delay 0.2
tell application "System Events"
keystroke "m" using command down
end tell
end repeat
end if -- if "MiniPlayer" is in iTunesWin_2
delay 0.2
-- unminimize active window of iTunes
if activeWin is not in iTunesWin_1 then
if activeWin is not "MiniPlayer" then
tell application "System Events"
tell process "iTunes"
if menu item activeWin of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.5
click menu item activeWin of menu 1 of menu bar item "Window" of menu bar 1
end if
end tell
end tell
end if
else -- activeWin is in iTunesWin_1, set active window to "iTunes"
tell application "System Events"
tell process "iTunes"
if menu item "iTunes" of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.5
click menu item "iTunes" 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.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
-- unminimize active window (run 1 of 1)
if activeApp is not "Safari" then
if activeApp is not in otherApps_2 then
delay 0.2
if activeApp is not in otherApps_3 or activeApp is not in otherApps_4 then
tell application "System Events"
tell process activeApp
set frontmost to true
delay 0.2
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 if
else -- activeApp is "Safari"
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.7
-- minimize windows
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 (firefox)
if (item 1 of otherApps) is not in activeApp then
tell application "System Events"
set frontmost of process (item 1 of otherApps) to true
delay 0.2
tell process (item 1 of otherApps)
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 if
end if
delay 0.2
if (item 2 of otherApps) is in openApps then -- item 2 of otherApps (vlc)
if (item 2 of otherApps) is not in activeApp then
if (item 2 of otherApps) is in otherApps_4 then
tell application "System Events"
set frontmost of process (item 2 of otherApps) to true
delay 0.2
tell process (item 2 of otherApps)
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 if
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
if (item 2 of otherApps) is in otherApps_4 then
tell application "System Events"
set frontmost of process (item 3 of otherApps) to true
delay 0.2
keystroke "m" using command down
end tell
end if
end if
end if
delay 0.2
if (item 4 of otherApps) is in openApps then -- item 4 of otherApps
if (item 4 of otherApps) is not in activeApp then
tell application "iTunes"
activate
delay 0.2
set activeWin to (get name of front window)
set iTunesWin_1 to {"Multiple Song Info", "Song Info"} -- cancel window
if activeWin is in iTunesWin_1 then
tell application "System Events"
key code 53
end tell
end if
delay 0.2
set iTunesWin_2 to (get name of every window)
if "MiniPlayer" is in iTunesWin_2 then
delay 0.7
if "iTunes" is name of front window then
tell application "System Events"
keystroke "m" using command down
end tell
else
tell application "System Events"
tell process "iTunes"
delay 0.2
click menu item "iTunes" of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 0.9
tell application "System Events"
delay 0.4
keystroke "m" using command down
delay 0.4
end tell
end if
set winCount to (count window)
if winCount is greater than 2 then -- windows: Activity,Equalizer
if "Activity" is in iTunesWin_2 then
tell application "System Events"
tell process "iTunes"
if menu item "Activity" of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.2
click menu item "Activity" of menu 1 of menu bar item "Window" of menu bar 1
end if
end tell
delay 0.2
keystroke "m" using command down
end tell
end if
if "Equalizer" is in iTunesWin_2 then
delay 0.5
if "Equalizer" is name of front window then
delay 0.4
tell application "System Events"
keystroke "m" using command down
delay 0.4
end tell
else
tell application "System Events"
tell process "iTunes"
delay 0.2
click menu item "Equalizer" of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 0.9
tell application "System Events"
delay 0.4
keystroke "m" using command down
delay 0.4
end tell
end if
end if
end if
else -- "MiniPlayer" is NOT in iTunesWin_2
set winCount to (count window)
repeat winCount times
delay 0.2
tell application "System Events"
keystroke "m" using command down
end tell
end repeat
end if -- if "MiniPlayer" is in iTunesWin_2
end tell
end if
end if
delay 0.7
-- min window of ATOM (text editor)
if "Atom" is in targetApps_1 then
tell application "System Events"
set myApp to "Atom"
tell process myApp
delay 0.2
set frontmost to true
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end tell
end tell
end if
delay 0.4
if "soffice" is in openApps then
if "soffice" is not activeApp then
tell application "System Events"
tell process "soffice"
set frontmost to true
tell application "System Events"
delay 0.2
keystroke "m" using {option down, command down}
end tell
end tell
end tell
end if
end if
delay 0.4
tell application "System Events"
tell process activeApp
delay 0.2
set frontmost to true
end tell
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"
-- fixed: Minimize window of OpenOffice.org
display notification "Release your finger" with title "my key 52.4"
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", "iTunes", "Atom", "soffice"} -- (item 1-4: Command + Option + M is not for minimizing all windows, item 5: Atom Helper got an error: Application isn’t running." number -600), item 6: error: error "Can’t get application \"soffice\"." number -1728 from current application
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 (firefox)
if (item 1 of otherApps) is not in activeApp then
tell application "System Events"
set frontmost of process (item 1 of otherApps) to true
delay 0.2
tell process (item 1 of otherApps)
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 if
end if
delay 0.2
if (item 2 of otherApps) is in openApps then -- item 2 of otherApps (vlc)
if (item 2 of otherApps) is not in activeApp then
tell application "System Events"
set frontmost of process (item 2 of otherApps) to true
delay 0.2
tell process (item 2 of otherApps)
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 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 "System Events"
set frontmost of process (item 3 of otherApps) to true
delay 0.2
keystroke "m" using command down
end tell
end if
end if
delay 0.2
if (item 4 of otherApps) is in openApps then -- item 4 of otherApps
if (item 4 of otherApps) is not in activeApp then
tell application "iTunes"
activate
delay 0.2
set activeWin to (get name of front window)
set iTunesWin_1 to {"Multiple Song Info", "Song Info"} -- cancel window
if activeWin is in iTunesWin_1 then
tell application "System Events"
key code 53
end tell
end if
delay 0.2
set iTunesWin_2 to (get name of every window)
if "MiniPlayer" is in iTunesWin_2 then
delay 0.7
if "iTunes" is name of front window then
tell application "System Events"
keystroke "m" using command down
end tell
else
tell application "System Events"
tell process "iTunes"
delay 0.2
click menu item "iTunes" of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 0.9
tell application "System Events"
delay 0.4
keystroke "m" using command down
delay 0.4
end tell
end if
set winCount to (count window)
if winCount is greater than 2 then -- windows: Activity,Equalizer
if "Activity" is in iTunesWin_2 then
tell application "System Events"
tell process "iTunes"
if menu item "Activity" of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.2
click menu item "Activity" of menu 1 of menu bar item "Window" of menu bar 1
end if
end tell
delay 0.2
keystroke "m" using command down
end tell
end if
if "Equalizer" is in iTunesWin_2 then
delay 0.5
if "Equalizer" is name of front window then
delay 0.4
tell application "System Events"
keystroke "m" using command down
delay 0.4
end tell
else
tell application "System Events"
tell process "iTunes"
delay 0.2
click menu item "Equalizer" of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 0.9
tell application "System Events"
delay 0.4
keystroke "m" using command down
delay 0.4
end tell
end if
end if
end if
else -- "MiniPlayer" is NOT in iTunesWin_2
set winCount to (count window)
repeat winCount times
delay 0.2
tell application "System Events"
keystroke "m" using command down
end tell
end repeat
end if -- if "MiniPlayer" is in iTunesWin_2
end tell
end if
end if
-- min window of ATOM (text editor)
if "Atom" is in targetApps_1 then
tell application "System Events"
set myApp to "Atom"
tell process myApp
delay 0.2
set frontmost to true
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end tell
end tell
end if
delay 0.4
if "soffice" is in openApps then
if "soffice" is not activeApp then
tell application "System Events"
tell process "soffice"
set frontmost to true
tell application "System Events"
delay 0.2
keystroke "m" using {option down, command down}
end tell
end tell
end tell
end if
end if
delay 0.7
tell application "System Events"
tell process activeApp
delay 0.2
set frontmost to true
end tell
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