Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Last active October 1, 2021 05:27
Show Gist options
  • Save bmidgley/68cc67eb189e13dd38d804a92eb7a966 to your computer and use it in GitHub Desktop.
Save bmidgley/68cc67eb189e13dd38d804a92eb7a966 to your computer and use it in GitHub Desktop.
Copy downloaded microbit hex file using a folder action
import os
import sys
import shutil
# Watch for a .hex file to appear in the Downloads folder
# when we see it, copy it to the microbit and then eject the drive
# the microbit will reboot with the new code running
# To install:
# Open Automator, File->New, Folder Action, Add "Run shell script"
# choose /usr/bin/python for the shell, paste this entire script in
# Save as Install Microbit Hex
# then from finder, open your home folder
# right-click Downloads, Services->Folder Actions Setup
# click Enable Folder Actions
# hit + and add Downloads (or just make sure the checkbox is selected)
# on the right panel, hit + and choose the script you just made, make sure it's checked
for filename in sys.argv[1:]:
if filename.endswith(".hex"):
shutil.copy(filename, "/Volumes/MICROBIT/")
os.system("diskutil unmount MICROBIT")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment