Much of my information came from this thread, very helpful:
http://ubuntuforums.org/showthread.php?t=502864
Several steps are involved and several locations will be accessed heavily. These are:
/etc/udev/rules.d - where the .rules file will be kept for the computer to access when the USB device of choice is plugged in, this ultimately points to the script file below
/usr/local - or wherever your script file is located.
/home/... - any other places where script files that will be used are stored, python, C etc
/etc/udev/rules.d
A README file is available in this folder and it is helpful to read. You will need to create a file here which will be picked up by your computer and read when an action occurs.
The file must begin with two digits followed by a - and end with .rules, 70-filename.rules. It will contain the following script:
ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="0d49", ATTRS{idProduct}=="7350", RUN+="/usr/local/script_file.sh", SYMLINK+="my_device"
If you are lost, just take a look at the files in /etc/udev/rules.d and make a similar filename.
To make it work for a specific device, with the device plugged in, run lsusb in a terminal and find the device Vendor and Product numbers. For the Kodak Co. device below, Vendor is 040a and the Product is 0576:
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 040a:0576 Kodak Co.
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000
The RUN+= is the location of your script file. It is very important that this file has user executable permission as well as for all other .py files etc that will be used by the script. To do this, go to the directory with the file and run:
$ sudo chmod u+x filename
and check the permissions with
$ ls -all
It should be: -rwxr--r--
These are the permissions that work for me, I'm not sure if this is across all platforms.
The location of the script file is not important, but make it an easy place to remember. SYMLINK+= is a feature I'm not familiar as yet, however it does allocate the device to the variable given to a spot in the /dev folder, /dev/Maxtor.
The ATTRS before {idVendor} and {idProduct} can be changed to SYSFS if the device is not being recognised once plugged in. This can only be tested by you and your product, although there may be better explainations about this.
The SUBSYSTEM variable can be left out completely, however it does give useful information to the computer. Other variables such as usb_device and pci... exist but usb is the one that works for me.
At first, it is advised to make the script file a simple copy code like a cp command of a file you know to a place you know. If after you plug in the device, you find that the file has been copied to the new destination, you can be sure that the .rules file has been successfully read. This is definately the hardest part of the setup of this 'autorun' script.
Before I wrap things up, I did want to add a work-around for the .sh file, the file pointed to by the .rules file. I had problems when plugging in my device because the .sh file would read first, and then any other code already on the computer would read last. This was a problem because I wanted to point to a folder on the device but the device hadn't been mounted yet. I could have mounted it myself but I ran into a dead end. An alternative was using the sleep command followed by my code, inside some curly braces {}, looking like this:
{
sleep 5
cp -ar /a/folder/on/my/computer /folder/on/device
} &
The {} tells the interpreter to read to code, but run it in the background. With the sleep command, there is a 5 second pause while the computer runs it's usual code of mounting the device. After the 5 seconds it now copies the folder to the location on the device.
If you have a know fix for mounting a device manually using the /dev location, I'd be happy to hear. I'm now using this method to auto update my Uni files on my external HD whenever I plug it in. This is my first How-To so enjoy, rate, comment.