
Show HN: Phoenix – a macOS window and app manager scriptable with JavaScript - khirviko
https://github.com/kasper/phoenix
======
city41
The window api makes me think one could pretty easily create an i3 like window
manager. But my past experience with OSX window managers like amethyst has
been subpar. Often the sizing/positioning is taken more as a “suggestion” by
the window than a command. I also found eventually windows would get into a
bad state. Has window management on OSX improved in the past couple years? On
Linux with X11, window managers truly have control and thus provide a more
reliable experience.

~~~
athorax
I have had a pretty stable setup using yabai[0] for my wm and skhd[1] for my
hotkey daemon. Both are by the same dev and I have nothing but good things to
say about them. Occasionally windows will get in a wonky state, but I have a
hot key to reset them. It is usually stable for a week+

[0][https://github.com/koekeishiya/yabai](https://github.com/koekeishiya/yabai)
[1][https://github.com/koekeishiya/skhd](https://github.com/koekeishiya/skhd)

~~~
Sir_Omnomnom
I've been using yabai and skhd for about a week, I was wondering what you are
using for your menu bar? I'm not really sure about a suitable replacement for
something like i3bar coming from Linux.

~~~
athorax
I have been using ubersicht[0]. The same developer of skhd/yabai has a
dotfiles repo that I mostly copied his config from.

[0][https://github.com/felixhageloh/uebersicht](https://github.com/felixhageloh/uebersicht)

------
guessmyname
The API [1] is an interesting read, as well as this thread from two years ago
[2].

I have used Spectacle [3] for years and recently switched to Rectangle [4].

These two are quite simple in comparison but I barely use all their features.

I have seen people using HammerSpoon [5] as well for these type of things.

Out of curiosity, what kind of things do people script in a window manager?

[1]
[https://github.com/kasper/phoenix/blob/bfcb684/docs/API.md](https://github.com/kasper/phoenix/blob/bfcb684/docs/API.md)

[2]
[https://news.ycombinator.com/item?id=16787836](https://news.ycombinator.com/item?id=16787836)

[3] [https://www.spectacleapp.com/](https://www.spectacleapp.com/)

[4] [https://rectangleapp.com/](https://rectangleapp.com/)

[5] [https://www.hammerspoon.org/](https://www.hammerspoon.org/)

~~~
heavyset_go
> _Out of curiosity, what kind of things do people script in a window
> manager?_

KWin is scriptable, and I use it to change window shading behavior and to do
some tiling. At one point I had it send SIGSTOP to processes that I minimized,
and SIGCONT when they were raised, to save battery life.

~~~
gigatexal
Oh man that is a nice little life hack!

------
fabiospampinato
Here's my configuration for Phoenix (with gifs):
[https://github.com/fabiospampinato/phoenix](https://github.com/fabiospampinato/phoenix)

You might find it useful as a starting point or as a source of inspiration.

~~~
newscracker
I got your link from an older post about Phoenix on HN. It’s really well done
(as some replies to you on the older thread said)!

Have you, by any chance, tried Hammerspoon (hammerspoon.org)? That seems to be
tool with a broader feature set compared to Phoenix. I was looking for some
kind of well analyzed and written comparison.

~~~
fabiospampinato
I have not tried Hammerspoon but I've skimmed through their docs, I'd say
ultimately it boils down to: do you want to write JS or Lua? And do you need
any of the Hammerspoon-specific features? I personally don't know any Lua and
actually quite like writing JS, I don't think I need any of extra features HS
provides, and with Phoenix you can still run a shell script and still achieve
many things HS provides explicitly.

------
zackmorris
I grew up in the 80s during the era of MacroMaker and QuickKeys, when you
could just hit the record button and make macros to play back sequences of
mouse and keyboard events. It was especially useful in programs like Photoshop
before they added their own macro systems. I'm having trouble finding links
about it:

[https://en.wikipedia.org/wiki/System_6#MacroMaker](https://en.wikipedia.org/wiki/System_6#MacroMaker)

[http://basalgangster.macgui.com/RetroMacComputing/The_Long_V...](http://basalgangster.macgui.com/RetroMacComputing/The_Long_View/Entries/2010/11/21_AppleScript.html)

The frontier was to eventually make everything scriptable and deterministic by
getting more apps to have hooks that could be controlled directly (so like a
specific command to click the close box of a window for example, rather than
sending a click event right and down from the top left corner).

Anyway, this whole concept of how to use computers seems to be all but dead
today and I can't help but feel that something of tremendous value has been
lost. Please, if you ever write macro tools like Phoenix, add a record
feature.

~~~
l_t
It does seem like we've realized that GUIs are not really the most automation-
friendly way to interact with programs. But there are a lot of nice macro
tools out there still.

For Windows, there is a macro scripting language Autohotkey [0], which has
powerful recording GUIs built on it [1]. Although it doesn't support
application-specific hooks that I'm aware of, it does allow introspection into
the rendered GUI of the application, so you can "click a button" instead of
"click a pixel".

OS X has Keyboard Maestro [2], which I've heard is good.

Also, many keyboards have macro recording built in. My Ducky keyboard can
record and save macros with no custom software/driver needed. (the macros can
even include mouse clicks, but that's a little janky.)

As a final note, I think the place I've seen macro recording still used the
most is in gaming. In most other areas of computing, it's seen as preferable
to make a special-purpose utility to solve a problem instead of building
layers of automation on top of a more general-purpose tool.

(btw, this is just based on my personal experience -- I love automation so
I've never been far from the macro-space. I'm not trying to argue against your
point.)

[0]: [https://www.autohotkey.com/](https://www.autohotkey.com/)

[1]: [https://www.macrocreator.com/](https://www.macrocreator.com/)

[2]:
[https://www.keyboardmaestro.com/main/](https://www.keyboardmaestro.com/main/)

~~~
capableweb
> It does seem like we've realized that GUIs are not really the most
> automation-friendly way to interact with programs. But there are a lot of
> nice macro tools out there still.

Yeah, in general the opinion seems to be "you want to manually do stuff, use a
GUI. If you want automation, use the API of either a server-side backend or
CLI tool", but there is a huge segment of users that are between that. Imagine
power users that don't know how to program. For them to be able to quickly
record > playback some common thing they do, would save a lot of time and be
valuable

------
ecliptik
Sloppy mouse focus? It’s the one feature I can never seem to find in macOS
window managers.

That and “highlight-to-copy” “middle-click-to-paste” are two things I really
miss from an X11 environment.

~~~
ken
Focus-follows-mouse, even sloppy, is problematic on macOS due to the menu bar.
Moving the mouse up to the menu bar means covering space which can belong to a
different window, which would change the meaning of the menu item when you got
there.

~~~
rsync
"Focus-follows-mouse, even sloppy, is problematic on macOS due to the menu
bar. Moving the mouse up to the menu bar means covering space which can belong
to a different window, which would change the meaning of the menu item when
you got there."

This is true, but easily surmountable.

Mondomouse, which is the last bona-fide focus-follows-mouse add-on that
existed for OSX (circa snow leopard) had a switch timer that was user-
definable.

So you could set the switch timer to .5 seconds or 1 second or something which
would allow you to run the mouse across other windows without changing focus.
That solved the menu bar problem that you are, correctly, pointing out.

I think it's also worth mentioning that if you're at the point where you're
demanding FFM, you're probably _already doing everything with hotkeys anyway_
so it's not like you're running up to the menu bar often ...

------
newscracker
Based on other links listed [1] in this comment right here and a little bit of
reading up, it seems like Phoenix focuses on window and app management whereas
Hammerspoon supports many more types of events and hooks to develop
actions/plugins on. Does anyone have a better comparison of these two?

[1]:
[https://news.ycombinator.com/item?id=22143917](https://news.ycombinator.com/item?id=22143917)

------
ketzo
Interesting, I need to check this out. I currently use Amethyst[1], and while
I like it, it’s definitely got some bugs/performance issues. I’ve also heard
people use chunkwm with good results, but haven’t tried it myself.

[1]ianyh.com/amethyst

~~~
jonfw
Yabai is the tool that replaced chunkWM, made by the same guy. You'd probably
want that one.

------
synthecypher
What can this do that Spectacle can't? Long time Spectacle user and JavaScript
developer here.

[https://www.spectacleapp.com/](https://www.spectacleapp.com/)

~~~
lrizzo
I have been using Spectacle for ages (with a custom javascript config, another
post...). The problem is, Spectacle uses a 32bit API that is scheduled to go
away and I am afraid that at some point (or 10.15 already?) it will stop
working.

------
Fnoord
Spectacle is another alternative on macOS [1]. There's also Amethyst. I'm not
sure which one's best. It is a matter of getting used to the default keybinds
IMO.

With Spectacle, the default keybinds are using Alt and Cmd as super key. I
like that one; I rather keep Caps Lock as Esc (else I'd use it as Ctrl).

As for i3, there's a backwards compatible Wayland successor called Sway [2].

[1]
[https://github.com/eczarny/spectacle](https://github.com/eczarny/spectacle)

[2] [https://github.com/swaywm/sway](https://github.com/swaywm/sway)

~~~
bobwaycott
> _I rather keep Caps Lock as Esc (else I 'd use it as Ctrl)._

Why not both? My caps is esc when pressed alone, but it’s ctrl when pressed in
combination with other keys. :)

~~~
Fnoord
Yeah, I'm using that, but I find it does not work well under high load.

------
robenkleene
You can do a lot of this stuff without a full app, you just need a way to
trigger an AppleScript with a keyboard shortcut. This is my framework for this
approach.
[https://github.com/robenkleene/windowpane](https://github.com/robenkleene/windowpane)

------
lrizzo
I have two links related to tiled window management:

The links are for WM configurations that let you move or resize windows
keeping the corners on a configurable grid:

[1] [https://github.com/luigirizzo/lrtile-
chrome](https://github.com/luigirizzo/lrtile-chrome) (chrome extension)
Ctrl+Shift+Arrow move the current window, Ctrl+Search+Arrows resize it

    
    
         This works for all Chrome windows so it platform independent. 
    

[2] [https://github.com/luigirizzo/lrtile-
cinnamon](https://github.com/luigirizzo/lrtile-cinnamon) (cinnamon extension,
linux) Alt+Arrows move the current window, Shift+Arrows resize it

(I have a similar Javascript configuration for Spectacle, I can post it if
there is interest. I believe the javascript is easily portable to other
scriptable window managers.)

My rationale for developing lrtile is the following:

I like having window corners on a grid because it helps locating information.

However, in many tiled WMs, resizing one window causes resizing of nearby ones
(very distracting) _and_ windows generally do not overlap (a severe limitation
especially on small screen). Finally, shortcuts to place windows on half or a
quarter of the screen are often built-in (in chrome, windows, spectacle
default...) but very few WMs have larger, configurable grids suitable for
large monitors (I use a 40" 4K screen).

lrtile addresses the above problems as follows:

\- the grid is configurable; \- movement/resize only affect the current
window, allowing overlap if user wants; \- commands are arrows + 1/2
modifiers, and try to be intuitive \- screen borders act as hard stops, also
making behavior more intuitive.

In detail, I typically use a 6x6 grid on small screens (so I can have halves
or thirds) and 12x10 or even bigger on large screens. Each window side must be
at least two units, and resize extends or reduces one dimension at a time and
by one unit.

My typical workflow is to make windows visible with a comfortable size and no
overlap, and occasionally expand the window I care about (e.g. make the
browser wider when a page does not render well; or expand the editor window
vertically when I want to see a larger chunk of code), reverting back when
done. The fact that move and resize commands are very similar to other cursor
movements makes the operation very quick.

------
xrd
Is there something similar for Linux? I was just reviewing Guile and thought
it would be something like that, but it isn't, and is Lisp. I would love
something similar on Linux.

~~~
omaranto
Gnome Shell is scriptable in JavaScript.

~~~
xrd
This just worked, I like it. Thanks!

[https://developer.gnome.org/gnome-devel-
demos/stable/dialog....](https://developer.gnome.org/gnome-devel-
demos/stable/dialog.js.html.en)

------
khirviko
So many good options nowadays! I think a few years ago, you would only find a
handful of projects focusing on similar matters.

------
jrs95
> JavaScript

Dear god, why? Don’t I have to suffer enough in my day job?

For real though this is a cool project despite my own personal JavaScript
fatigue.

~~~
tonyedgecombe
It could be worse, it could have been AppleScript.

~~~
ken
Wouldn't that be better? Anything you can script with AppleScript (OSA) you
can also script with JavaScript, but not the other way around.

------
tomThom
which takes more memory (and is slower)? LISP interpreter or v8/node?

------
simplify
Not to be confused with Phoenix[0], the Rails-like web framework for
Elixir/Erlang.

[0]: [https://www.phoenixframework.org](https://www.phoenixframework.org)

~~~
mrspeaker
I don't think anyone will be confused... seeing as it's also the name of about
a billion other things (Pre-Firefox, I still remember you!). I feel like
"Pheonix" is the second most common project name behind "Matrix".

And on a less nit-pick-y note if the author is reading this - the project
looks really fun and is certainly going to take up a chunk of my weekend!

~~~
khirviko
Cool! Let me know what you come up with. :)

