19 Sep 2016

Automate your macOS with Hammerspoon

Posted on September 19, 2016

I’ve been using macOS for about 8 years and as a dual monitor user there was always a very annoying problem which I could never find a perfect solution for. Every time I connected or disconnected my second monitor from my MacBook, macOS messed up the window positions.

Then I discovered Hammerspoon and was not only able to fix this problem but also able to automate a lot of cool things and I was also able to replace HardwareGrowler with it.

My configuration is a available at github and provides the following features:

  • Notifications for hardware events (USB, battery, WiFi, volumes)
  • Window layout for single and dual monitor setups
  • Connect or disconnect Bluetooth when the second monitor is plugged or unplugged (blueutil must be installed)
  • growlnotify replacement: hammerspoon://notify?title=...&subtitle=...&info=...
  • Open new Chrome window for development: hammerspoon://devopen?url=http://....

This configuration is work in progress and there will be more features in the future.


git clone https://github.com/code2k/.hammerspoon.git ~/.hammerspoon
cd ~/.hammerspoon
cp example-config.lua config.lua

Then edit config.lua as needed.

7 Jan 2015

Twitter Cleanup

Posted on January 7, 2015

Happy New Year everyone! My first blog post of 2015 will help you to cleanup your following list on Twitter. The goal is to only follow someone if you are interested in their Twitter content or if they are following you back. Everyone else will be unfollowed.

To achieve this I wrote a little script which will do this automatically for you. Before you can run it for the first time you will have to do some preparations though.

First create a new list on Twitter and add everyone to it who should not be unfollowed no matter if they are following you or not. By default this list is called ‘Reading’ but you can change it to whatever you like by changing the KEEPLIST variable in the script.

Then install the excellent command-line Twitter tool T and authorize it to use your Twitter account. You need to register a Twitter app for that. For more information please have a look at the T documentation.

Download the script and execute the following commands in the terminal:

chmod 744 twitter-clean.sh


8 Apr 2014

Update your npm packages with the help of Vim

Posted on April 8, 2014

I’m a big fan of yeoman for generating new projects for my web applications especially if I want to do a quick prototype. But there is one thing that bothers me. Nearly all generators are using old package dependencies which makes it really hard to find the proper documentation if you have to customize the build process.

There are many options to update the dependencies, here is a quick way to do it with the help of Vim:


Open the package.json file in Vim and first of all go to the first line of the dependencies and start recording a macro using qq. Record the following macro:

  • f": find the first ‘”’
  • x: delete it
  • ;: find the next ‘”’
  • C: delete till the end of the line and enter insert mode
  • @latest: append the version indicator to the package name
  • ESC
  • J: join the next line with the current line

Stop recording the macro by pressing q and just run the macro 20 times by pressing [email protected]. Copy the resulting line into the clipboard and use it with the following command (use :q! to exit Vim):

npm install --save-dev <paste packages here>

This is maybe not the best way to do this but it is a nice Vim exercise for sure.