Autostart Mautrix/iMessage BlueBubbles Connector at Boot Using Cron


Important!

Follow the setup guide here created by @ampersandru and @matchstick.

For autostart with launchd follow this guide by @shadowdrake:beeper.com.

Creating a script to start the bridge

My script to start the bridge will be located in /Users/Shared/start-bridge.sh

The script is as follows: be sure to run chmod +x ./start-bridge.sh to make it executable. This script also assumes bbctl is already in your path from following the setup guide.

1
2
3
4
5
#delay bridge from starting to allow BlueBubbles to start and system to boot up
#edit number of pings as needed
ping -c 40 127.0.0.1
#start bridge
bbctl-<your-version> run --param 'bluebubbles_url=http://localhost:1234' --param 'bluebubbles_password=your_password' --param 'imessage_platform=bluebubbles' sh-imessage

Replace your_password with your actual BlueBubbles password. Be sure to also enter the correct name of your bbctl executable.
I'm using ping here as a way to delay the start of the server until the Mac has fully booted up, if you have a newer or faster Mac you can possibly adjust the number of pings or remove this line.

Setting up cron

  1. Grant Full Disk Access to cron see here:
    https://medium.com/vunamhung/granting-full-disk-access-to-cron-29d2267fbe62
  2. Grant Full Disk Access to Terminal.app

Now open a terminal window and run:

echo $path
Make note of this output, this is everything in your path and will be important soon.

Now in the same Terminal window type:

export EDITOR=nano - This can be skipped if you are wise enough to know how to exit vi 😉

Now finally type: crontab -e

Paste the following in obviously you'll want to modify PATH with what is in your path while keeping the same syntax. You'll also want to modify the location of your bridge start script to where it resides on your system. I personally keep mine alongside bbctl.

1
2
3
SHELL=/bin/bash
PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local
@reboot /Users/Shared/start-bridge.sh >> /Users/Shared/cron.log 2>&1

Once you are sure everything is working after rebooting and testing edit the crontab and remove:
>> /Users/Shared/cron.log 2>&1
This is so the log file doesn't grow unbounded. For debugging purposes it can always be added back in the future. To see if the bridge is running check Activity Monitor for bbctl-<your-version> etc.


Here's a bonus shell script to restart your bridge without a command window:
Run chmod +x on this script prior to usage. Change paths relevant to your setup.

Restart-Bridge.sh

pkill bbctl-<your-version>
nohup /Users/Shared/start-bridge.sh &

Obviously change for your architecture and paths.

Special thanks to @matchstick for help with this guide.

Edit
Pub: 05 Feb 2024 23:24 UTC
Edit: 13 Feb 2024 22:12 UTC
Views: 923