obb

borkdude 2022-01-11T11:51:55.007600Z

Does anyone know how to get the size of your display with JXA? I'm trying to make an example by adapting this script: https://lukas-domagala.de/blog/cljs-to-jxa-for-automation.html (/cc @domagala.lukas) to move Emacs to the left of the screen and my Google Chrome to the right of the screen. It would make a pretty nice example of how to lay out certain apps by creating a little script for it.

Lukas Domagala 2022-01-11T12:34:05.011Z

I’ve been looking at that problem for the post. It’s not that hard to get your whole setup size:

tell application "Finder"
	get bounds of window of desktop
end tell
=> {0, 0, 6272, 1440}
But as you can see, you don’t really get each monitor. This thread https://forum.latenightsw.com/t/get-sizes-of-monitor-s-via-applescript/1351/3 has solutions for multiple monitors, but I didn’t have the patience to translate them into jxa.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set allFrames to (current application's NSScreen's screens()'s valueForKey:"frame") as list
=> {{{0.0, 0.0}, {2560.0, 1440.0}}, {{4480.0, 193.0}, {1792.0, 1120.0}}, {{2560.0, 240.0}, {1920.0, 1200.0}}}

borkdude 2022-01-11T12:35:57.011300Z

I could find lots of applescript examples, but I don't know how to translate it into JXA

borkdude 2022-01-11T12:36:11.011500Z

For example this one:

tell application "Finder"
	get bounds of window of desktop
end tell

borkdude 2022-01-11T12:46:14.011700Z

Got it!

$ obb -e '(def finder (js/Application "Finder")) (def bounds (.bounds (.window (.-desktop finder)))) (prn bounds)'
#js {:x 0, :y 0, :width 1680, :height 1050}

🙌 1
Lukas Domagala 2022-01-11T12:48:04.011900Z

yeah translating the applescript examples has been the most frustrating thing, especially once they get more complicated. applescript syntax is truly any interesting experience.

zane 2022-01-11T19:57:10.014100Z

I find it’s easiest to just work your way through it iteratively. That’s part of why I want to get REPL support up and running soon.

borkdude 2022-01-11T19:57:34.014300Z

yeah, but I didn't even know where to start.

borkdude 2022-01-11T19:57:55.014500Z

as I had trouble finding this API. If I know the API, I can iterate pretty quickly by just executing snippets

zane 2022-01-11T19:59:17.014700Z

Got it! Makes sense.

Lukas Domagala 2022-01-11T21:39:55.014900Z

Searching for applescript was usually a lot better than jxa, just more annoying to translate

borkdude 2022-01-11T12:58:10.012800Z

OK, cool, here is a layout example, which moves my Emacs + Chrome side by side. https://github.com/babashka/obb/blob/main/examples/layout.cljs https://twitter.com/borkdude/status/1480886560929288195

🆒 6
ordnungswidrig 2022-01-18T11:12:39.001400Z

I think I might be able to replace phoenix eventually 😉