Skip to content

Instantly share code, notes, and snippets.

Created October 11, 2017 06:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/60ba21088ab7ef730db6bf41a4a7cc6c to your computer and use it in GitHub Desktop.
Save anonymous/60ba21088ab7ef730db6bf41a4a7cc6c to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<root>
<item>
<name>My Key 52.7: 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"
-- name of script: Minimize All Windows But Active Window
-- fixed: Minimize windows of iTunes 12.7.0.166
-- fixed: when iTunes 12.7.0.166 is activeApp
display notification "Release your finger" with title "my key 52.7"
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 OneWindowApps to {"Folder Lister", "VLC", "VideoSpec", "Dictionary", "fSync", "Karabiner Preferences", "iTunes", "Atom"} -- if activeApp is in OneWindowApps, script killed for no reason)
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.02
if activeApp is in OneWindowApps then -- run script: min all but open windows of active app
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
if activeApp is "iTunes" then
-- min windows of iTunes and unmin active window
tell application "System Events"
set activeWindowiTunes to name of front window of process "iTunes"
set subWiniTunes to {"MiniPlayer", "Multiple Song Info", "Song Info"}
if activeWindowiTunes is in subWiniTunes then
set activeWindowiTunes to "iTunes"
end if
set iwindows to name of window of process "iTunes"
set iwindowsCount to count iwindows
if iwindowsCount is greater than 1 then
tell process "iTunes" -- cancel window "Multiple Song Info" or "Song Info"
set frontmost to true
key code 53
end tell
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
set target to {"iTunes", "Activity", "Equalizer"}
repeat with w in target
delay 0.04
(windows where title is w)
if result is not {} then perform action "AXRaise" of item 1 of result
(windows where title is w)
if result is not {} then
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end if
end repeat
end tell
end tell
else -- min one window
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
keystroke "m" using command down
end tell
end tell
end if
delay 0.2
-- unmin activeWindow of iTunes
tell application "System Events"
tell process "iTunes"
if menu item activeWindowiTunes of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.2
click menu item activeWindowiTunes of menu 1 of menu bar item "Window" of menu bar 1
end if
end tell
end tell
end tell
end if
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
-- min windows of iTunes
tell application "System Events"
set iwindows to name of window of process "iTunes"
set iwindowsCount to count iwindows
if iwindowsCount is greater than 1 then
tell process "iTunes" -- cancel window "Multiple Song Info" or "Song Info"
set frontmost to true
key code 53
end tell
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
set target to {"iTunes", "Activity", "Equalizer"}
repeat with w in target
delay 0.04
(windows where title is w)
if result is not {} then perform action "AXRaise" of item 1 of result
(windows where title is w)
if result is not {} then
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end if
end repeat
end tell
end tell
else -- min one window
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
keystroke "m" using command down
end tell
end tell
end if
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
else -- end of script: min all but open window of active app
tell application "System Events" -- start script - min all but active window
delay 0.5
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
delay 1
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
-- min windows of iTunes and unmin active window
tell application "System Events"
set activeWindowiTunes to name of front window of process "iTunes"
set subWiniTunes to {"MiniPlayer", "Multiple Song Info", "Song Info"}
if activeWindowiTunes is in subWiniTunes then
set activeWindowiTunes to "iTunes"
end if
set iwindows to name of window of process "iTunes"
set iwindowsCount to count iwindows
if iwindowsCount is greater than 1 then
tell process "iTunes" -- cancel window "Multiple Song Info" or "Song Info"
set frontmost to true
key code 53
end tell
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
set target to {"iTunes", "Activity", "Equalizer"}
repeat with w in target
delay 0.04
(windows where title is w)
if result is not {} then perform action "AXRaise" of item 1 of result
(windows where title is w)
if result is not {} then
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end if
end repeat
end tell
end tell
else -- min one window
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
keystroke "m" using command down
end tell
end tell
end if
delay 0.2
-- unmin activeWindow of iTunes
tell application "System Events"
tell process "iTunes"
if menu item activeWindowiTunes of menu 1 of menu bar item "Window" of menu bar 1 exists then
delay 0.2
click menu item activeWindowiTunes of menu 1 of menu bar item "Window" of menu bar 1
end if
end tell
end tell
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
-- min windows of iTunes
tell application "System Events"
set iwindows to name of window of process "iTunes"
set iwindowsCount to count iwindows
if iwindowsCount is greater than 1 then
tell process "iTunes" -- cancel window "Multiple Song Info" or "Song Info"
set frontmost to true
key code 53
end tell
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
set target to {"iTunes", "Activity", "Equalizer"}
repeat with w in target
delay 0.04
(windows where title is w)
if result is not {} then perform action "AXRaise" of item 1 of result
(windows where title is w)
if result is not {} then
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end if
end repeat
end tell
end tell
else -- min one window
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
keystroke "m" using command down
end tell
end tell
end if
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 if
-- END of Script-Minimize All Windows But Active Window
Script-Minimize All Windows But Open Windows of Active App:
tell application "System Events"
-- name of script: Minimize All Windows But Open Windows of Active App
-- fixed: Minimize windows of iTunes 12.7.0.166
display notification "Release your finger" with title "my key 52.7"
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 - iTunes
if (item 4 of otherApps) is not in activeApp then
-- min windows of iTunes
tell application "System Events"
set iwindows to name of window of process "iTunes"
set iwindowsCount to count iwindows
if iwindowsCount is greater than 1 then
tell process "iTunes" -- cancel window "Multiple Song Info" or "Song Info"
set frontmost to true
key code 53
end tell
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
set target to {"iTunes", "Activity", "Equalizer"}
repeat with w in target
delay 0.04
(windows where title is w)
if result is not {} then perform action "AXRaise" of item 1 of result
(windows where title is w)
if result is not {} then
tell application "System Events"
delay 0.2
keystroke "m" using command down
end tell
end if
end repeat
end tell
end tell
else -- min one window
tell application "System Events"
tell process "iTunes"
set frontmost to true
delay 0.2
keystroke "m" using command down
end tell
end tell
end if
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