Skip to content

Instantly share code, notes, and snippets.

@wzulfikar
Last active November 2, 2022 18:24
Show Gist options
  • Save wzulfikar/ba2f58d7aeeb3cf53743316f96f91594 to your computer and use it in GitHub Desktop.
Save wzulfikar/ba2f58d7aeeb3cf53743316f96f91594 to your computer and use it in GitHub Desktop.
Notes

Hello world! 🌎

I write notes in this gist as comments. My original goal was to have a workflow where I can't have an excuse to not write. No websites to manage, no codes to push, no styles to update. Just write. I found Github gist fitting and I don't have issues with writing markdown.

This gist contains "problem-based", technical notes. I encounter a problem, I "google" the solution, I document the solution. Hopefully, I can accumulate the learning and don't have to google again when I encounter the same problem.

Besides problem-based, I also write my "TIL" notes here. They are the new things I learnt that often gave me that "nice" feeling when I first found about it.

There are other things I write like electronics, observations, etc. which I put in different gists. If you want to check it, here's the "sitemap" of all my notes:

flowchart TD
  Notes --You are here--> Problem-based[<strong>Problem-based</strong>]
  Notes -.-> Observations
  Notes -.-> Logs
  Notes -.-> Challenges
  Notes -.-> Electronics

  click Problem-based "https://gist.github.com/wzulfikar/ba2f58d7aeeb3cf53743316f96f91594"
  click Observations "https://gist.github.com/wzulfikar/2cff9bcd64ba5f15296e0b57ff402f79"
  click Logs "https://gist.github.com/wzulfikar/5ea5779d7f2ea0e27809e94e7904f93d"
  click Challenges "https://gist.github.com/wzulfikar/7d5e9426d1c7efc3ceeabb29adb2f4fd"
  click Electronics "https://gist.github.com/wzulfikar/16c3b5f10b8f28d8b0e325d03c948d1c"
Loading

Problem-based · Observations · Logs · Challenges · Electronics

▲▼▲

@wzulfikar
Copy link
Author

wzulfikar commented Oct 18, 2022

Wed, Oct 19, 2022
🧶 Problem: I want macOS to trigger a backup script when I plug in a microSD
💡 Solution: Use Apple Automator to trigger rsync
🔗 Ref: Apple Support Community
#️⃣ Tags: macOS automator workflow
🔢 Encounters: 1

Context:
I have 2 cameras that I use to record videos (DJI Pocket 2 and Akaso Brave 7). After recording some videos, I'll:

  1. take out the microSD from the camera
  2. plug it in to my card reader
  3. copy the videos to my SSD (I use rsync for this)
  4. plug out the microSD and put it back to the device.

I noticed the pattern and I thought it'd be good if I can automate number 3. I know I can trigger a script when a device mounted using systemd (eg. this gist) but macOS doesn't have systemd. So I googled and found the discussion in Apple Support Community (see Ref). Turns out I can us Automator for that.

image

Automator script:

device=$(basename $@)
script=/Volumes/wzulfikar/Devices/$device/sync.sh

[ ! -f "$script" ] && exit 1

osascript -e "display dialog \"Syncing $@..\" giving up after 5"

$script

osascript -e "display dialog \"Sync completed for $@\""

sync.sh script (eg. located in /Volumes/wzulfikar/Devices/DJIPOCKET2/sync.sh):

#!/bin/sh

source=/Volumes/DJIPOCKET2/DCIM/
target=/Volumes/wzulfikar/Devices/DJIPOCKET2/DCIM/

echo "Syncing $source to $target"

rsync -rP --ignore-existing $source $target

▲▼▲

When doing this, I also learnt that Automator stores its scripts in ~/Library/Workflows/Applications. Here's how my Folder Actions script look like in that directory:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment