Connect to Bluetooth device via terminal
As there are some upvotes and many views, I will answer my own question there:

Yes, it is possible to write some small application in Swift or ObjC which does this. And some people did that already:


BluetoothConnector
blueutil


BluetoothConnector is written in Swift, which does (currently) only support connecting and disconnecting (It seems to be pretty new, so more features may follow some day).

blueutil is written in Objective-C. In addition to (dis-)connecting it can also toggle power, discoverability, show if you are already connected, etc.

I tried both, and both worked well, currently I'll stick with blueutil - it has more features, which come in handy in shell scripts.