Simpler1 / sd-autocopy

SD card autocopy (Linux)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SD card autocopy

Copying photos from the SD card of my camera is a very common task. And always the same pattern. Take the card out of the camera, put it into the sd card reader, wait for the automount popup, browse to the picture directory, select all images, cut all images, browse to my photo directory, create a new folder, name the folder, move to the folder, paste the pictures into it, wait for the finished job.

Sound boring? Sure, it is!

Now, how to make this one a little smarter? Maybe scripting some of those steps is a cool idea. So how would this work in a perfect world?

The idea

Taking the SD card out of the camera and putting it into the SD card reader does not seem to be easily scripted, that's why I focused on the other steps ;-). Okay, I'd like to put the card into the reader, just wait for all the images to be moved and then put the card back into the camera.

But how to reach this goal? Maybe you're interested in my solution...

Get the USB device unit

Plug in the usb drive and run

systemctl --all list-units

$ systemctl --all list-units
  UNIT                                                                                                                  LOAD      ACTIVE   SUB       DESCRIPTION                                                                        
● boot.automount                                                                                                        not-found inactive dead      boot.automount                                                                     
  dev-disk-by\x2did-usb\x2dTS\x2dRDF5_SD_Transcend_000000000039\x2d0:0.device                                           loaded    active   plugged   SD_Transcend                                                                       
  dev-disk-by\x2did-usb\x2dTS\x2dRDF5_SD_Transcend_000000000039\x2d0:0\x2dpart1.device                                  loaded    active   plugged   SD_Transcend FIELD_CAM                                                             
  dev-disk-by\x2dlabel-FIELD_CAM.device                                                                                 loaded    active   plugged   SD_Transcend FIELD_CAM                                                             
  dev-disk-by\x2dpartuuid-1cae7fd0\x2d01.device                                                                         loaded    active   plugged   SD_Transcend FIELD_CAM                                                             

In this example the device unit is: dev-disk-by\x2dlabel-FIELD_CAM.device

$ cat /usr/lib/systemd/system/sd.service 
[Unit]
Description=Copy photos from SD card when inserted
Requires=dev-disk-by\x2dlabel-FIELD_CAM.device
After=dev-disk-by\x2dlabel-FIELD_CAM.device

[Service]
ExecStart=/usr/local/bin/sd-copy

[Install]
WantedBy=dev-disk-by\x2dlabel-FIELD_CAM.device

Copy the sd-copy script from this repository and make the script executable:

chmod +x /usr/local/bin/sd-copy

Manually unmount and remove the USB device.

Now simply plug the SD card of your choice into your SD card reader and plug the card reader into the USB port.

About

SD card autocopy (Linux)


Languages

Language:Shell 100.0%