Created
June 7, 2020 16:54
-
-
Save mals14/2ba1cd76e6649742ef946c110cfc84d8 to your computer and use it in GitHub Desktop.
applescript resize Finder windows.applescript
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
# ideas from New Finder windows - Questions & Suggestions - Keyboard Maestro Discourse | |
# https://forum.keyboardmaestro.com/t/new-finder-windows/3048/2 | |
# to merge current windows | |
(* what is being done here | |
Check if Finder windows exist. | |
If two windows exist, then set them to be in bound1 and bound2. | |
If more than one window exists, then merge them all. Copy the active tab. Close the active tab. Set bounds to bound1. | |
Then open a new window with active tab path. Set bounds to bound2. | |
*) | |
# set _number_of_windows to number of Finder windows | |
set win1Bounds to {790, 23, 1677, 520} # top finder window | |
set win2Bounds to {790, 521, 1677, 1049} # lower window | |
set winTarget01 to (path to desktop folder) | |
set winTarget02 to (path to downloads folder) | |
set _finder_window_count to the count of (the windows of application "Finder") | |
log "Number of Finder windows is " & _finder_window_count | |
# toggle get info window | |
tell application "System Events" to tell process "Finder" | |
set frontmost to true | |
keystroke "i" using {command down, option down} | |
delay 1 | |
end tell | |
set _finder_window_count_after_toggle to the count of (the windows of application "Finder") | |
log "Number after toggle " & _finder_window_count_after_toggle | |
# find out if get info window is open | |
if _finder_window_count < _finder_window_count_after_toggle then | |
# toggle get info window | |
log "Get info window was open - closing it." | |
tell application "System Events" to tell process "Finder" | |
set frontmost to true | |
keystroke "i" using {command down, option down} | |
end tell | |
delay 1 | |
end if | |
# set finder window count again | |
set _finder_window_count to the count of (the windows of application "Finder") | |
log "Number of Finder windows after get info test is " & _finder_window_count | |
if _finder_window_count > 2 then | |
tell application "Finder" | |
if exists Finder window 1 then | |
set currentDir to (target of Finder window 1) | |
else | |
set currentDir to (path to desktop folder) | |
end if | |
end tell | |
tell application "System Events" | |
tell process "Finder" | |
click menu item "Merge All Windows" of menu "Window" of menu bar 1 | |
end tell | |
end tell | |
delay 1 | |
tell application "System Events" | |
tell process "Finder" | |
click menu item "Close Tab" of menu "File" of menu bar 1 | |
end tell | |
end tell | |
(* No need to size window here and no delay needed therefore | |
delay 2 | |
tell application "Finder" | |
tell front window | |
if bounds is not win1Bounds then | |
set bounds to win1Bounds | |
end if | |
end tell | |
end tell | |
*) | |
(* not using it because what is closed is not the tab that has been duplicated | |
# close the active tab as its path has been copied | |
tell application "System Events" | |
tell process "Finder" | |
click menu item "Close Tab" of menu "File" of menu bar 1 | |
end tell | |
end tell | |
*) | |
set winTarget02 to currentDir | |
tell application "Finder" | |
set newWin02 to make new Finder window | |
tell newWin02 | |
# set bounds to {0, 521, 870, 1018} | |
# set bounds to win2Bounds | |
if toolbar visible ≠ true then set toolbar visible to true | |
set its target to winTarget02 | |
if its current view ≠ list view then set its current view to list view | |
end tell | |
end tell | |
else if _finder_window_count = 2 then | |
(* | |
tell application "Finder" | |
tell window 1 to set bounds to win1Bounds | |
delay 1 | |
tell window 2 to set bounds to win2Bounds | |
end tell | |
*) | |
else if _finder_window_count = 1 then | |
(* | |
tell application "Finder" | |
tell front window | |
if bounds is not win1Bounds then | |
set bounds to win1Bounds | |
end if | |
end tell | |
end tell | |
*) | |
tell application "Finder" | |
set newWin02 to make new Finder window | |
tell newWin02 | |
# set bounds to {0, 521, 870, 1018} | |
# set bounds to win2Bounds | |
if toolbar visible ≠ true then set toolbar visible to true | |
set its target to winTarget02 | |
if its current view ≠ list view then set its current view to list view | |
end tell | |
end tell | |
else if _finder_window_count = 0 then | |
tell application "Finder" | |
set newWin01 to make new Finder window | |
tell newWin01 | |
# set bounds to {0, 23, 870, 520} | |
# set bounds to win1Bounds | |
if toolbar visible ≠ true then set toolbar visible to true | |
set its target to winTarget01 | |
if its current view ≠ list view then set its current view to list view | |
end tell | |
set newWin02 to make new Finder window | |
tell newWin02 | |
# set bounds to {0, 521, 870, 1018} | |
# set bounds to win2Bounds | |
if toolbar visible ≠ true then set toolbar visible to true | |
set its target to winTarget02 | |
if its current view ≠ list view then set its current view to list view | |
end tell | |
# set index of newWin01 to 1 # not doing this | |
end tell | |
end if | |
(* module to activate get info window | |
tell application "Finder" | |
open information window of item 1 of window 1 | |
end tell | |
*) | |
# module to activate Alt Get info window | |
tell application "System Events" to tell process "Finder" | |
set frontmost to true | |
keystroke "i" using {command down, option down} | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment