Autostart `rclone mount` on macOS - easy way

Purely programmatic way to achieve it is to use launchd framework (macOS equivalent of Linux systemd). But not everybody is familiar with command line voodoo.

macOS automation tools come to the rescue here.

The easiest way is to use Shortcuts.

Create very simple Shortcut with Run Shell Script building block and fill in there your rclone mount command (plus --daemon flag). You must provide full path to rclone executable. If not sure where it is run which rclone command in terminal for the answer.

$ which rclone
/usr/local/bin/rclone

Click here to add above example to your Shortcuts. Or create your own from scratch.

When you have your Shortcut ready, right click on it and select Add to Dock. Behind the scenes this operation bundles your workflow in an .app file and drops it under ~/Applications/.

Once your Shortcut icon has been added to the Dock, you can right-click it and select Options -> Open at Login. This adds a new entry to Login Items and can be verified in System Preferences under Login Items.

You can keep or remove now your shortcut app icon from the Dock.

Every time you restart your mac this Shortcut will be executed on login and mount your rclone remote.

This sample Shortcut provides very basic functionality - it would be advisable to add for example check if your mac is connected to the network etc. If anybody creates something more sophisticated and clever please share your work so others less advanced users can benefit.

3 Likes

please add the sleep command too, it works!

On some computers network might not be fully available when such Shortcut starts. In such case simple solution is to delay it by some time:

speep 30; /usr/local/bin/rclone mount remote: /path/to/mountpoint --daemon

It can be solved in more sophisticated way if somebody feels like writing few clever bash lines. But simple sleep works too.

Below improved script part - waiting for network availability:

#!/bin/bash

while ! ping -c 4 google.com > /dev/null; 
do
  sleep 1 
done

/usr/local/bin/rclone nfsmount crypt: /Users/Shared/mount --vfs-cache-mode=full --vfs-cache-max-size=10GiB --vfs-refresh --volname="My crypt mount" --daemon

And here link to add this as a shortcut to macOS.

1 Like