Category Archives: Software

Backing up a macOS home directory using launchd

Apple Time Machine can be used to make backups of the whole computer. Launchd serves to start a process at specified intervals and can be used make regular backups of a certain directory, for example your home directory.

The example below starts a bash script every 10 minutes, which calls rsync to do the actual backup over ssh. I implemented this to back up to a Raspberry Pi with a large USB disk attached. It requires the public/private ssh keys to be shared between the two machines.

The bash script /usr/local/bin/backup2fileserver.sh contains the following:

#!/bin/bash
/sbin/ping -c 1 -q fileserver.local || exit 1
/usr/bin/rsync -a /Users/robert robert@fileserver.local:/media/backupdisk/

I made the plist file /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist with launchd instructions to start the script every 600 seconds using this online launchd plist generator. It contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.zerowidth.launched.backup2fileserver</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>/usr/local/bin/backup2fileserver.sh</string>
</array>
<key>UserName</key>
<string>root</string>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>

Subsequently I used the following command in the macOS terminal to tell launchd to manage the backup script:

sudo launchctl load -w /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist /Library/LaunchDaemons/com.zerowidth.launched.backup2fileserver.plist

Native Python implementation for Unicorn wireless EEG data

This page is part on a series on the Unicorn EEG system, see also the other posts.

The Unicorn EEG system is a low-cost wireless 8-channel EEG system including an IMU and the “naked” version lends itself well to making your own 3d-printed enclosure as I demonstrated here. Most important for me is that it “just works”.

As the software that comes with only works on Windows and I prefer macOS, I made a platform-independent native Python implementation for real-time data streaming. My example streams the data to LSL, but can also be used as a starting point for real-time processing. See the gist of unicorn2lsl.py on GitHub.

Using the Bela to measure the frequency response

Bela is a maker platform for creating beautiful interactions. It consists of a Beaglebone black, with a shield or hat that has 2 audio inputs, 2 audio outputs, 8 analog inputs, and 8 analog outputs. It is complemented with a very slick web interface that allows you to write and very easily compile and run your code. And very cool is that the web interface features an oscilloscope.

I am planning to build a purely analog EEC/EMG/ECG amplifier, similar to this design on Instructables. As that involves making choices on the filter settings: a low-pass filter to remove electrode drift, a notch filter for line noise, high-pass anti-aliasing filter matched to audible frequencies. Hence I started thinking on how to determine the combined effect of all those filters, together with the multiple amplifier stages. It occurred to me that the Bela can act both as a signal generator and as a digital recorder and oscilloscope.

Bela and breadboard with fiter

On this GitHub page I am sharing a Bela project that outputs a sine wave on the analog output, which can be fed through an external circuit, and subsequently measured using the analog inputs. The project computes a real-time discrete Fourier transform of the output signal and compares the amplitude and phase to the input signal. Using a LaunchControl XL MIDI controller (or alternatively using a small EEGsynth path for an on-screen MIDI controller), I can select the frequency, and start/stop a sweep over the whole frequency range. The amplitude and phase response at each frequency is logged to disk.

Continue reading