Hammerspoon
This is a modal window.
Das Video konnte nicht geladen werden, da entweder ein Server- oder Netzwerkfehler auftrat oder das Format nicht unterstützt wird.
Formale Metadaten
Titel |
| |
Serientitel | ||
Teil | 97 | |
Anzahl der Teile | 110 | |
Autor | ||
Lizenz | CC-Namensnennung 2.0 Belgien: Sie dürfen das Werk bzw. den Inhalt zu jedem legalen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen. | |
Identifikatoren | 10.5446/31011 (DOI) | |
Herausgeber | ||
Erscheinungsjahr | ||
Sprache |
Inhaltliche Metadaten
Fachgebiet | |
Genre |
FOSDEM 201697 / 110
4
6
10
11
13
15
17
19
20
23
25
27
30
32
36
38
39
41
42
43
44
45
46
47
48
50
52
54
58
61
62
69
71
72
75
76
78
79
80
82
87
88
91
93
94
95
96
97
101
103
104
106
107
110
00:00
Mini-DiscDiskrete-Elemente-MethodeMeterMultiplikationURLFunktion <Mathematik>SchedulingFunktionalFormale GrammatikRechter WinkelPhysikalisches SystemE-MailSoftwareentwicklerInterface <Schaltung>BildschirmfensterMultiplikationsoperatorWort <Informatik>Geneigte EbeneApp <Programm>RechenbuchKartesische KoordinatenDatenverwaltungSoftwareSpider <Programm>FontMenütechnikTouchscreenTermComputerschachSpielkonsoleLeistung <Physik>Zentrische StreckungData MiningDrucksondierungProzess <Informatik>Radikal <Mathematik>Twitter <Softwareplattform>Demo <Programm>BitStreaming <Kommunikationstechnik>Coxeter-GruppeElektronische PublikationMathematikInteraktives FernsehenFramework <Informatik>ClientQuaderFlächeninhaltPrimitive <Informatik>EreignishorizontCodeArithmetische FolgeLokales MinimumTabelleGlobale OptimierungÄhnlichkeitsgeometrieBimodulAuflösung <Mathematik>Überlagerung <Mathematik>Formale SemantikEndliche ModelltheorieWeb SiteVerschiebungsoperatorURLProgrammierungFitnessfunktionDirekte numerische SimulationProgrammfehlerHook <Programmierung>Profil <Aerodynamik>BrowserGraphische BenutzeroberflächeKonfigurationsraumMinimumOpen SourceSchreiben <Datenverarbeitung>XMLComputeranimation
08:31
Modul <Datentyp>BenutzeroberflächeZahlenbereichWrapper <Programmierung>Automatische HandlungsplanungMultiplikationsoperatorTypentheorieProgrammbibliothekDatenverwaltungFitnessfunktionSkriptspracheSchnittmengeCodeObjekt <Kategorie>Prozess <Informatik>Elektronische PublikationMetropolitan area networkBitrateHoaxGrundsätze ordnungsmäßiger DatenverarbeitungFramework <Informatik>BildschirmfensterTouchscreenBimodulKonstanteGüte der AnpassungKeller <Informatik>DickeTermTwitter <Softwareplattform>SoftwareentwicklerHilfesystemProgrammiergerätTabelleServerDreiecksfreier GraphRechter WinkelKartesische KoordinatenSystemaufrufNormalvektorSystemplattformElement <Gruppentheorie>Interface <Schaltung>CASE <Informatik>Humanoider RoboterWikiWeb SiteFunktionalMereologieMailing-ListeGeradet-TestKlasse <Mathematik>Wort <Informatik>AggregatzustandVersionsverwaltungComputerspielSpezielle unitäre GruppePasswortTermersetzungssystemKonfigurationsraumApp <Programm>ZweiElektronischer ProgrammführerWhiteboardInteraktives FernsehenGraphische BenutzeroberflächeSchreiben <Datenverarbeitung>Repository <Informatik>Richtung
16:58
GoogolSpeicherabzugComputeranimation
Transkript: Englisch(automatisch erzeugt)
00:05
Okay, we're back to our schedule. Wait for the light, yes, that's fine.
00:23
Yes, yes, almost there. This is just for the stream, right? Yes. Okay, let me first start off by saying this presentation is done in Lua. We wrote the presentation framework a week ago and it is not stable.
00:48
It also doesn't scale perfectly to this Beamer, but I think we'll deal. So what is HammerSpoon? HammerSpoon is, as we like to say, staggeringly powerful desktop automation.
01:01
Most people, when they hear about it and we explain what it is, they think it is a window manager, like in Linux with X11. It is not like that, if only because OS X already has a window manager. But you can manage your windows with HammerSpoon, so I'll show some of that later.
01:20
Who am I? Also, interesting maybe, my name is Peter van Dyck. I work for PowerDNS. Any PowerDNS users in here? Cool. We also use a lot of Lua, so if you have any DNS problem and you would like to apply some Lua to it, check our stuff out. It's all GPL, all open source.
01:41
Besides that, I have contributed to some of the predecessors of HammerSpoon. There is a long history of software going before it, and today I am mostly passively involved in HammerSpoon. Most development is being done by Chris Jones, who could not be here, sadly. So what is it? How does HammerSpoon fit together?
02:04
OS X has a lot of system APIs for window management, audio management, file management. We expose all of those to Lua, with simple interfaces when we can. Not just for you to call, but also for system event handlers to call your code.
02:21
You can hook together a lot of things, and I'll show some examples later. Some history. Like I said, there have been a couple of programs before. Stephen DeGutes came into the Lua IRC channel one day, and he said, I am writing a window manager in Lua, who wants to help me. So I had been thinking about something like that as well, so I joined in.
02:46
He then wrote, I think it was called Hydra at the time. But he changed the name every three months, changed the whole concept every three months. His last incarnation was Mjolnir. It was very minimal, and any functionality you wanted, you had to install via Lua Rocks.
03:06
So if you look on Lua Rocks today, you will see a lot of packages with Mjolnir as a prefix. We thought this was not what users wanted, so HammerSpoon, right now, every module that is available for it, shifts with it.
03:23
So that's easier to use. This is some text from Stephen. This is a WebView, rendered on top of this slide. We have a WebView module you can do this with. So you have Hydra, Phoenix, Zephyrus, Mjolnir. Those are all the old apps.
03:42
All Lua. Has anybody used any of these other apps? Just two? Then we'll skip this. It won't make sense then. So what can you do? You can do window management. You can react to events like a changed SSID. You could, for example, disable your Twitter client because it streams data.
04:06
You don't want this on every network you're at. You can react to USB devices being plugged in or removed. You can monitor folders for file changes, etc. You can interact with application menus. For example, a friend of mine, when he clicked on a URL in his terminal, he wanted to choose which Chrome profile to load it in.
04:30
You can't do that by just handling URLs. You need to talk to the Chrome application, go to the people menu at the top and click the right one. Then wait half a millisecond and then send the URL, etc.
04:43
You cannot do all these things, although sometimes it's quite hacky. You can draw custom interfaces. I have one picture of that later on. As I said, you can do some URL handling. You can make HammerSpoon your HTTP handler or Mailto or whatever, and then do whatever you like.
05:05
I'm just launching some applications. I hope this will make sense at this resolution. Has anybody used TmaxoMatic? Yeah, a couple of users. This configuration on this side will make some sense to you.
05:23
MuleMatic, written from Mjolnir, named after TmaxoMatic. You map your applications to single letters and then you draw your whole screen layout in ASCII. I should have used fix with font, but I didn't manage to fix that.
05:42
This is one configuration that has chess, the top right, nodes, bottom left, etc. This is just an example of a thing that could be written inside HammerSpoon. It's not the main functionality. Here's another config, and of course that also works. You see some quirks here. These are not all because of the Beamer.
06:03
Like the calculator app, it is fixed size. If you have a tiling window manager or any other kind of window manager that wants to arrange your screen neatly, you will run into these things. The calculator has a fixed size, chess has a minimum size, nodes have a minimum size.
06:21
These are all things you don't notice normally when you just drag stuff around. But when you start automating, these things can hurt. In a similar way, terminal applications don't really have a minimal size or fixed size. But they have steps in their sizes because of the font inside.
06:40
We actually found some bugs in iTerm in that area, but they got fixed. Here's one example. I hope you can read it. I'll zoom. This is actually the code for what I mentioned earlier. You make a new Wi-Fi watcher, you pass a function to it, because it's Lua, we can do this.
07:01
And when it fires, something has happened to the Wi-Fi. Either you got disconnected or you got connected. If you got disconnected, network is nil, so we can alert Wi-Fi disconnected and otherwise you can say we joined the network. And then you can say, well, this is my home network, so please launch the Twitter app. Or this is not my home network, please kill it because I don't want all the alerts, I don't want it to sit there streaming, consuming data, etc.
07:27
So this is an idea of what you can do, but you can of course do many more things. This is an example of both the custom drawing we can do and the URL handling.
07:41
This is a thing Chris wrote. When he clicks the URL, this thing pops up. It shows every application willing to open URLs, including iTerm and Hammerspoon. So he should probably filter that out. And then you can just push one for Firefox or four for Safari, etc.
08:03
And Hammerspoon provides all the primitives to pick up this event, find these applications, draw this menu, and in the end, fire up the right browser. We have a command line interface. I will zoom that in. It is a bit like the Lua console, of course. It talks to your running Hammerspoon process.
08:27
I have a couple of demos here of other functionality we have. You can manage the baseboard. Sadly, you have to pull it if you want to react to people copying. There is no API in OS X for getting a trigger.
08:41
You can manage audio devices. In this case, I have just shown the name of my current one. You can get your GPS location. Well, I guess in OS X it is not GPS, but Wi-Fi-based, as you probably know. You can do all the usual Lua stuff, like counting the length of a table to count the number of Chrome processes.
09:04
For some reason, I don't know. It says four while I had two. This happens only with Chrome. We have JavaScript, because there is a JavaScript framework in OS X, so we hooked that up too. If you really want to, you can write JavaScript in Lua, in Hammerspoon, without moonshine.
09:27
This is a list of all the other modules we have. Maybe if you see something you like, you can call it out and I will say a few words.
09:45
UI elements. UI elements. All right. UI elements is not for drawing. It is for interacting with elements in other windows. There is a dialog here. It has windows. It has buttons. Take them to that button, then click it, etc.
10:04
So that goes beyond the interaction we had with the menus on top. You can interact with any element in an application if needed. This, of course, is quite fragile, because applications change over time. Yes?
10:21
Redshift. Redshift changes your screen tint over time to match the sun. Yes? The password manager, the auto-type doesn't work on Mac OS.
10:43
You can make something with this that types in passwords. Yes. So there is some example code. I can find it for you later. Because some applications, some websites, they disable your paste functionality.
11:04
So with a couple of lines of Lua, you can make a second paste button that actually types out your paste board. So yes, you can do that. Right. Try it. Anything else?
11:25
No? Yeah? The HTTP server would allow for some kind of API that plays with your desktop? Well, there is something between that. The HTTP server gets requests. Those turn into Lua calls. And then you may decide later to make those Lua calls do things to your windows.
11:45
But it is not just a window manager. And with the HTTP server, you can post things to your Lua code if you like. I am not sure why, but there are users, I guess.
12:00
Any more? Okay. Moving on. HammerSpoon is written in Objective-C, like most Mac apps, I guess. Chris has developed a very thin Lua wrapper for Objective-C. It is currently inside HammerSpoon. He does not have plans to take it outside, but he thought I should show you anyway.
12:26
I hope this makes sense to you. My Objective-C is not great. There is some example code. Creating a Lua state, destroying it, basic lifecycle management.
12:41
You can call the normal Lua C API on your object still if you like. Of course, any protection we give you in terms of stack management then goes out the window. We have some helpers for making libraries, class objects, class methods.
13:00
Let us see what else. This is not my code, so it is hard for me to say useful things about it. We have some helper functions for working with tables. If you have a use for this, please talk to Chris and tell him to rip it out and take it outside. Until then, I guess it is staying inside because it is just easier for development.
13:25
That is all I got. Questions? Yes? It is like tips and tricks, something useful that can be just copied and reused.
13:44
The question was, are there any example scripts? Yes, there are many. Chris Jones, the main developer currently, is on a mission to replace 15 different tools he had with little snippets of Lua and he polishes his configs.
14:00
I think on our GitHub Wiki there is a list of various people's Hammerspoon configs with all the cool stuff they do with it. I think our GitHub Wiki is the best place. Or just hammerspoon.org and click the right buttons.
14:22
Are there any GitHub repo or something like that? Our website is a GitHub repo, but I think the examples are in the GitHub Wiki mostly. Also, we have a getting started guide on the site, which is quite good I think. Any plans of taking this to other platforms?
14:45
Any plans of taking this to other platforms? I think it would basically mean a rewrite. I am also not sure how many of the modules could actually be re-implemented with the same interface on another platform. So we don't have plans.
15:01
I have pondered, do you know Tasker for Android? Tasker is an automation tool for Android with which you can tie some things together. From what I have seen it involves a lot of tapping and a lot of magic constants. I have thought that Lua might be a good fit there, but that's just a wild idea. We have no plans, no.
15:26
I have a question. What about putting those snippets in luroc so you can answer them with a single line? If we had a set of snippets that was suitable for installation in such a way, we would ship it with the app I guess.
15:45
Just so your user base could contribute snippets. Like that, yeah. Lua rocks does work with our stuff. We ship our internal Lua, but it searches all the normal parts. That could work.
16:01
Yeah. Which you have with Objective-C. In other words, what I am trying to figure out here is where a poorly written config will potentially expose native Objective-C calls.
16:27
We don't expose native Objective-C calls directly. There is no FFI. We just have a bunch of wrappers with interfaces that make the most sense to us as Lua programmers.
16:40
I guess you could do FFI if you wanted to. I haven't checked. Any more? Okay, thank you.