Skip to content

Instantly share code, notes, and snippets.

@Dima-369
Last active February 7, 2021 18:54
Show Gist options
  • Save Dima-369/3a8fa43b54ef9a6f612e585bea2ee0dc to your computer and use it in GitHub Desktop.
Save Dima-369/3a8fa43b54ef9a6f612e585bea2ee0dc to your computer and use it in GitHub Desktop.
Open 2 Finder windows side by side in Hammerspoon
-- using real hyper with shift breaks some hotkeys for whatever reason
hyper = {"cmd", "alt", "ctrl"}
-- workaround from https://github.com/Hammerspoon/hammerspoon/issues/2099#issuecomment-490503167
function execAppleScript(scpt)
local scpt = 'run script ((POSIX file "' .. scpt .. '") as alias)'
hs.osascript.applescript(scpt)
end
hs.hotkey.bind(hyper, "n", function()
execAppleScript('/Users/Gira/dotfiles/mac/two-finders.scpt')
end)
-- based on https://copiancestral.wordpress.com/2012/03/24/two-finders-side-by-side/
tell application "Finder"
set targetFolder to POSIX file "/Users/Gira/"
-- get number of open finders
set NumberofFinders to count every Finder window
if NumberofFinders is 0 then
make Finder window to targetFolder
end if
set screenWidth to 1440
set screenHeight to 900
-- move finder and set the size
set the position of the front Finder window to {0, 0}
set the bounds of the front Finder window to {0, 0, screenWidth * 0.5, screenHeight * 0.9}
-- make second finder
make Finder window to targetFolder
set the target of Finder window 1 to home
set the position of the front Finder window to {screenWidth * 0.5, 0}
set the bounds of the front Finder window to {screenWidth * 0.5, 0, screenWidth, screenHeight * 0.9}
-- bring the finders to the front
activate
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment