Sending notes from Laptop to Phone with kdeconnect-cli and rsync
What is this?
One-way sync of a directory of (mostly) text files from my laptop to my android phone, using bash, kdeconnect-cli and rsync. I use [Markor] in my phone as my notes app to read the files of the synced directory.
Why?
- Cos, clouds disappear.
- Cos, it’s cheap and fast
- Cos, privacy
- Cos, it makes you diligent with your notes
- And cos, it’s cool
Why one-way and why not 2-way?
Cos I’m too dumb to figure it out over a weekend, plus I don’t want the stress of handling merge-conflicts and remembering which source to pull from and push to, while also the fear of the data getting erased due to my mistake just overwhelms me. I’m not young. I don’t need this anxiety in my life.
But how do you manage notes from your phone?
I just use whatever default notes app there is in my phone and jot down things as they come up to my mind, in a single file in that app.
The next time I’m on my laptop, I just move that text to relevant files in my notes dir, and delete the contents from my phone’s notes.
How?
a bash script in my PATH that I can invoke from anywhere while the phone and the laptop are connected over the same wifi, and the kdeconnect app is running on both devices
Gimme the technical deets!
kdeconnect-cli -a --id-name-onlyto get the name and id of my phone used by the kdeconnect app- paths:
- path prefix of where the phone’s filesystem gets mounted onto the laptop’s filesystem
- path of the phone’s storage where you want your source dir to end up (the destination dir’s path)
- a text file used by rsync that has the files/dirs you want to exclude from sending to the phone
- A list of directories you want to send to your phone
- Finally, rsync these to the phone, and you’re done!
Share the full script please
Here you go!
#!/usr/bin/env bash
# push some dirs from laptop to phone via kde connect over same wifi.
set -euo pipefail
phone_name="your-phone-name-in-kdeconnect"
phone_id=""
id_and_name=($(kdeconnect-cli -a --id-name-only))
if [[ "${id_and_name[1]}" == "${phone_name}" ]]; then
phone_id="${id_and_name[0]}"
else
printf "can't find phone!\n"
exit 1
fi
phone_mounted_path="/run/user/$(id -u)/${phone_id}"
phone_internal_storage_path="/storage/emulated/0"
# push ~/Documents to phone's internal memory
src_path="${HOME}/Documents"
dest_path="${phone_mounted_path}${phone_internal_storage_path}/Documents/from_laptop"
printf "1) rsyncing src:${src_path} ==> dest:${dest_path} ..."
rsync -avz \
--exclude-from="${HOME}/bin/push_to_phone_exclude_list.txt" \
"${src_path}" "${dest_path}/"
If you want to send more folders, then just copy paste the last block and change stuff as needed.
Put this script in a file, give it a really short name, chmod it so it becomes executable, and put it in your $PATH.
You’re done.