How can I connect my MacBook to a bluetooth speaker using KM?

Every time I put my Mac to sleep, it loses connection to my bluetooth speaker and I have to manually reconnect the two devices.
I need a macro that can help me automate the reconnection steps on the MacBook. These include:

  1. Opening the bluetooth preference pane
  2. Selecting the bluetooth speaker
  3. Right-clicking and selecting connect

Can a simple script or macro perform all these steps?

Here are some ideas: