Auto-Copy script

Joined
Aug 6, 2009
Messages
5
Reaction score
0
Points
1
I am fairly computer literate & have some knowledge of UNIX scripts from the past......


I have been a windows/PC user forever, but bought a Mac laptop a year ago after my PC laptop broke....brilliant decision!

Anyway, I use external hard-drives to back up my large digital library of photographs....I use a windows batch file located on the hard drive that runs automatically when I plug it in the USB port on the PC....it works perfectly.

I am wanting to ditch the PC, and move to MAC completely, but I still need to be able to have the ability to plug in a USB drive, it copy the desired directories I wish to it.

How do I get a script located on the USB drive to automatically run when I plug in a USB drive? :Confused:


I actually have no idea where to start! I can figure out the 'cp' comands myself, but getting the script to 'call' in the firstplace I am lost.....!
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,596
Reaction score
1,072
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
Joined
May 22, 2005
Messages
2,159
Reaction score
67
Points
48
Location
Closer than you think.
Your Mac's Specs
Performa 6116 2GBSCSI 8MB OS 7.5.3
What is calling the batch file? Surely a batch file cannot execute itself when a drive is inserted.

You'd need to create some sort of launch agent or daemon to be listening for USB connectivity.

Is it a specific drive or any USB drive? Does it prompt you for input?
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,596
Reaction score
1,072
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
I am just starting to look at this and I'm not much of a scripter that is why I was going to use Automator. Here is one way the script could probably be called. Perhaps others can chime in with the specifics till I have a chance to work out the details:

There is an invisible folder on the Mac called /Volumes When a drive mounts it will appear there. The script would check for the correct drive and either execute or not depending upon whether the right drve is present. Once the script is written it can be saved as a folder action. Folder actions execute when there is a change to a specific folder
Folder Actions for OS X explained – with real-world examples – Simple Help
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,596
Reaction score
1,072
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
Should have known you would pick up the ball and run with it. lol. I had forgotten about Do Something When.
 
OP
S
Joined
Aug 6, 2009
Messages
5
Reaction score
0
Points
1
thanks for info.....

w.r.t. the batch file, I wrote a basic DOS batch file, and it is located on any external drive you wish to put it on. When you plug a drive in on windows, you can select an action it will carry out every time 'that particular drive' is connected. I simply set it to execute the batch file I have saved on the drive. I will look in to the folder actions, but would like to achieve this before buying an iMac!

I would have to refresh my memory with my UNIX commands, but the script would simply be 'cp' commands.....with switches only to copy updated/changed files......

e.g.

cp /switches /Users/stevenjparkes/Pictures ./ and re-direct the output to some.log
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top