How can I automatically copy files to a USB drive when I connect it to my computer?
You can quite easily build your own solution for Windows using autorun.inf and a .bat file.
Create a bat file to copy a directory to your usb drive.
xcopy /e /y c:\podcasts\*.* .\dir_on_usb_drive
Place the bat file on your mp3 player and create an autorun.inf using these instructions
Now you should have your own homebuilt solution to your problem but it's certainly possible that there's pre-made solutions out there :)
For Linux:
If you don't mind a little Python scripting you could write a daemon that listens to HAL for events and then launches a script once a device of your choice has been plugged in. An example script would look like this:
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import dbus
import dbus.service
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
import gobject
import sys
import os
class DeviceManager:
def __init__(self):
self.bus = dbus.SystemBus()
self.bus.add_signal_receiver(self.device_added,
'DeviceAdded',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
self.bus.add_signal_receiver(self.device_removed,
'DeviceRemoved',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
def udi_to_device(self, udi):
return self.bus.get_object("org.freedesktop.Hal", udi)
def device_added(self, udi):
print 'Added', udi
properties = self.udi_to_device(udi).GetAllProperties()
if properties.get('info.category') == u'volume':
label, dev = properties.get('volume.label'), properties.get('block.device')
print 'Mounting %s on /media/%s' %(dev, label)
os.system('pmount %s /media/%s' %(dev, label))
def device_removed(self, udi):
print 'Removed', udi
if __name__ == '__main__':
m = DeviceManager()
mainloop = gobject.MainLoop()
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()
print 'Exiting...'
sys.exit(0)
You just have to modify the device_added()
function to limit it to the specific device and replace the os.system()
call with your custom script.
For limiting it to the drive the volume.uuid
property could be used and a full list of available properties can be displayed with the hal-device
program.
To start the daemon on boot, just start it from /etc/rc.local
.
Windows 7 and autosync to your flash/USB device on insert!
Download SyncToy and establish your folder pairing and sync name("SyncTest")
see: How-to: Using SyncToy to make a nightly mirror of My Documents
- Run computer management console
- Event viewer/windows logs/system
- Find the media insertion event
- “The Portable Device Enumerator Service service entered the running state.” (You may need to clear you event log and eject/reinsert you media to trigger this log event)
- In the upper event window, right click on the event and select "Attach Task To This Event"
- Windows open "Create Basic Task Window"
- Give your task a name and hit next
- Event information is already filled in, next
- Action should show "Start a Program", next
- In the Start a Program window, browse to SyncToyCmd.exe(or your chosen sync app)
- Add arguments. If your backup pairing is called SyncTest, enter "-RsyncTest". Do not add quotes, do not add a space after the -R, SyncToy command line(or maybe Windows 7) is case sensative so SyncTest does not equal synctest!
- Next, Finish
You can run the task right from Task Scheduler to verify it works. Now the only other problem I had was running my laptop on batteries, in Task Manager under the conditions tab, uncheck "Start the task only if the computer is on AC power", otherwise task will only run when AC is plugged in.
Also, as USB polls and disconnects/reconnects, this task will run every couple of minutes, actually kinda cool, it's auto-syncing to the USB HDD all the time :)