You have to pass with echo (with option -e) the commands you want to execute. Every command you have to terminate it with a new line (\n). When I do connect I use the tab (\t) so that I do not need to update the script with the MAC of my keyboard.
#!/bin/bash
# enable bluetooth
sudo systemctl start bluetooth
sleep 1
# run the program bluez
echo -e 'power on\nconnect \t \nquit' | bluetoothctl
sorry if it's a dumb question but I haven't found anything around
]]>