Last active
September 26, 2024 20:03
-
-
Save ClementGre/9f422d96e716af67be51210d2210906b to your computer and use it in GitHub Desktop.
Phoenix MacOS script to keep finder window on the desktop it was opened on (instead of switching between desks due to a bug of MacOS).
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
// Utils | |
function getWindowSpace(window){ | |
return Space.all().find(s => s.windows().find(w => w.isEqual(window))) | |
} | |
function getSpaceFromHash(hash){ | |
return Space.all().find(s => s.hash() === hash) | |
} | |
// Default space definition | |
Event.on('windowDidOpen', (window) => { | |
if(window.app().name() == 'Finder'){ | |
let space = getWindowSpace(window) | |
if(space){ | |
Storage.set(window.hash(), space.hash()); | |
} | |
} | |
}); | |
// Space definition with Control + Option + S | |
Key.on('s', ['option', 'control'], () => { | |
const window = Window.focused(); | |
if(window.app().name() == 'Finder'){ | |
let space = getWindowSpace(window) | |
if(space){ | |
Storage.set(window.hash(), space.hash()); | |
} | |
} | |
}); | |
// Move window to default space | |
Event.on('spaceDidChange', () => { | |
// Iterate over all windows in all spaces | |
Space.all().forEach(space => space.windows().forEach(window => { | |
if(window.app().name() == 'Finder'){ | |
let defaultSpace = getSpaceFromHash(Storage.get(window.hash())) | |
if(defaultSpace && !space.isEqual(defaultSpace)){ | |
defaultSpace.moveWindows([window]) | |
} | |
} | |
})) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment