LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Automatically copy images off digital camera (https://www.linuxquestions.org/questions/linux-software-2/automatically-copy-images-off-digital-camera-358879/)

taboom 08-31-2005 01:14 PM

Automatically copy images off digital camera
 
I haven't found any programs doing this (in Linux):
- when a camera is connected (and recognized) it
- creates a folder according to the images/computers date (and checks that one doesn't exist, else it makes a [date-x] folder, where x is a rising number)
- copies all images to this folder
- asks permission to delete the images (or not, should be possible to specify)
- informs about the actions taken/openes the downloaded images folder should also be possible to specify).

I can't see this could be anything hard to create, but will I need to make this script myself, or is it just that I can't find this kind of a program? It could certainly exist, as this is something ppl probably want.

Thank's in advance

shane25119 08-31-2005 01:41 PM

Well, I know that each time I plug my memory card into my card reader on my Ubuntu Desktop it offers to copy all the images off of the memory card for me. I'm not sure on the name of the program that pops up with that one... I'm on a laptop at school now and it's quite difficult to get Linux working here so I am using Windows... ugh... if no one else posts the name of that program I will check it when I get home tonight and post it for you.

S

rose_bud4201 08-31-2005 02:08 PM

Gphotolib, once you've set it up initially, will do all of that in about 3 commands. If you've not gotten gphoto set up yet I got a little verbose when doing mine and posted it all here.

That said, here's a little script which doens't have a whole lot of error checking (you can do that yourself if it gets to be a hassle), but which will do what you want:

Code:

#!/bin/bash

# Camera all plugged in and ready?  Good!

today=`date +%m%d%Y`
if [[ ! -e "./Photos" ]]; then
  mkdir ./Photos
fi

if [[ -e "./Photos/$today/" ]]; then
  echo "./Photos/$today/ exists!"
  increment=1
  echo "checking to see if ./Photos/$today-$increment exists..."
  while [ -e "./Photos/$today-$increment" ]; do
        echo "./Photos/$today-$increment exists!"
        let increment=increment+1
  done
  filename="./Photos/$today-$increment/"
else
  filename="./Photos/$today/"
fi
echo "filename = $filename"
mkdir $filename
cd $filename
num_photos= `gphoto2 --num-files`
num_photos=30
gphoto2 --get-all-files
echo "Downloaded $num_photos pictures to $filename!"
echo "Would you like to remove them from the camera (Y/N)?"
read delete
if [[ $delete == "Y" ]]; then
    gphoto2 --delete-all-files
    echo "Successfully deleted all files."
fi

Edit pathnames, echo's, etc as you like (naturally). As for the "opens the downloaded folder", I wasn't going to put that in there simply because not everyone has an application which will do that (I certainly don't). If you're running Gnome, you could stick a line like

nautilus --no-desktop $filename &

in there at the end, which I think would accomplish the task.

rose_bud4201 08-31-2005 02:18 PM

As an afterthought, the --delete-all-files isn't all that reliable (I thought it was just me that it didn't work for, but google says otherwise).

May I instead substitute something like
gphoto2 --delete-file 0-$num_photos

or, failing even that, put it in a loop:
for i in `seq 0 $num_photos`; do
gphoto2 --delete-file $i
done

I don't remember if they start at 0 or 1, I used 0 for argument's sake.

taboom 08-31-2005 02:24 PM

Thank's for the script, I actually already started (or almost finished) coding one myself. The only problems I have are:
- echoed out messages don't appear anywhere
- i'd like to use kde's widgets, like a confirming before deleting, but obviously need to do learn kde coding before this
- I cannot delete with gphoto2 for some reason, it just doesn't delete (even if it succesfully does this command)
- delete-all fails as there is a "theme.dat" on my camera, which is impossible to delete.

On digikam I can delete pictures, but not the theme.dat file

It seems as this is known (deleting the theme.dat file), I remember seeing an error report on this issue somewhere. I have an Ixus 700 and it seems as development for its drivers are also a bit behind currently, but digikam can delete "normal" files!

But thanks fot the script anyway. I'd really be interested in knowing what prog ubuntu uses (I use debian myself)

rose_bud4201 08-31-2005 02:29 PM

Yeah, the delete-all-files has a known issue (see my post after that one). You won't be able to use graphical buttons in a bash script; if you want that, just use gtkam (gphoto2's GUI) instead.

The echo'd messages will appear on the commandline, the same place from which you started the script...
Code:

[laura@cleopatra ~/work]$ ./camera.sh
./Photos/08312005/ exists!
checking to see if ./Photos/08312005-1 exists...
./Photos/08312005-1 exists!
./Photos/08312005-2 exists!
./Photos/08312005-3 exists!
./Photos/08312005-4 exists!
filename = ./Photos/08312005-5/
Downloaded 30 pictures to ./Photos/08312005-5/!
Would you like to remove them from the camera (Y/N)?
Y
Successfully deleted all files.
Exiting...
[laura@cleopatra ~/work]$

That's slightly hacked-up, as I don't have my camera plugged in so all of the calls to gphoto2 are commented out and the number of photos is hard-coded, but the meat of the script is still running.

Edit: I see that I left all of the "checking to see if.." debug lines in there. They ought to have been commented out, too. D'oh.

taboom 08-31-2005 02:38 PM

Oh yes, I obviously didnät explain myself..
If I make it start automatically, with hotplug by activating it with files in:
Code:

/etc/hotplug/usb/autocopy.usermap
# Canon Digital IXUS 700
autocopy          0x0003      0x04a9  0x30f2    0x0000      0x0000      0x00        0x00            0x00            0x00            0x00              0x00              0x00000000

and
Code:

/etc/hotplug/usb/autocopy
!/bin/bash
if [ "$ACTION" = "add" ] && [ -f "$DEVICE" ]
then
#do all stuff
---snip--
fi

Now, where does the echoed out messages show? - in a console I never see...

rose_bud4201 08-31-2005 03:07 PM

Ohhhh, I see what you mean. Honestly, I'd just use the GUI or run the script manually when you plug the camera in....it's made for running froma commandline, not for background tasks (the fact that you want to give it input means you'll have to run manually). I haven't the faintest idea where output like that goes, but I've a hunch that it's /dev/null. You won't be able to respond to a program like that, either, so you'd better hardcode the deletion of files to either on or off so it doesn't hang waiting for your response.


All times are GMT -5. The time now is 01:35 PM.