Skip to content

Instantly share code, notes, and snippets.

@ClementGre
Created May 3, 2023 11:49
Show Gist options
  • Save ClementGre/9f422d96e716af67be51210d2210906b to your computer and use it in GitHub Desktop.
Save ClementGre/9f422d96e716af67be51210d2210906b to your computer and use it in GitHub Desktop.
Phoenix MacOS script to keep finder windows on the desktop it were opened on (instead of switching between desks due to a but of MacOS Ventura).
// 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