Results 1 to 7 of 7
  1. #1
    Registered User
    Member Since
    Aug 06, 2009
    Posts
    5
    Auto-Copy script
    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?


    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.....!

  2. #2

    Slydude's Avatar
    Member Since
    Nov 16, 2009
    Location
    North Louisiana, USA
    Posts
    9,235
    Specs:
    2.8 GHz MacBook Pro 10.11, 8 GB mem, iPhone 6+
    I am going to try this with Automator soon but until I have time to work on it these references might get you started. The second link is based upon using an excellent backup program called Super Duper. I suspect either script would be east to modify.

    Use a run-on-drive-connect SuperDuper backup script - Mac OS X Hints

    SuperDuper Bash Script to Automatically Mount or Unmount a Hard Drive ? T?N?T Luoma
    Sylvester Roque Former Contributing Editor About This Particular Macintosh

    "Got Time to breathe. You got time for music." Denver Pyle as Briscoe Darling

  3. #3

    MacsWork's Avatar
    Member Since
    May 22, 2005
    Location
    Closer than you think.
    Posts
    2,159
    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?

  4. #4

    Slydude's Avatar
    Member Since
    Nov 16, 2009
    Location
    North Louisiana, USA
    Posts
    9,235
    Specs:
    2.8 GHz MacBook Pro 10.11, 8 GB mem, iPhone 6+
    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
    Sylvester Roque Former Contributing Editor About This Particular Macintosh

    "Got Time to breathe. You got time for music." Denver Pyle as Briscoe Darling

  5. #5

    McYukon's Avatar
    Member Since
    May 14, 2009
    Location
    Near Whitehorse, Yukon
    Posts
    2,052
    Specs:
    2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
    Here's a example that is almost what your wanting to to,
    Autorun finder when plugging in USB Stick - MacRumors Forums
    Use the reputation system if a post helps you!
    Mac Forums IRC Channel - Help build it by hanging out with us
    The next sentence is true. The previous sentence is false.

  6. #6

    Slydude's Avatar
    Member Since
    Nov 16, 2009
    Location
    North Louisiana, USA
    Posts
    9,235
    Specs:
    2.8 GHz MacBook Pro 10.11, 8 GB mem, iPhone 6+
    Should have known you would pick up the ball and run with it. lol. I had forgotten about Do Something When.
    Sylvester Roque Former Contributing Editor About This Particular Macintosh

    "Got Time to breathe. You got time for music." Denver Pyle as Briscoe Darling

  7. #7
    Registered User
    Member Since
    Aug 06, 2009
    Posts
    5
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with simple Automator file copy script
    By PBear in forum OS X - Apps and Games
    Replies: 0
    Last Post: 04-20-2012, 11:09 PM
  2. Terminal -- shell script -- script will only read two lines of a file
    By Straitsfan in forum OS X - Apps and Games
    Replies: 0
    Last Post: 01-30-2011, 10:04 PM
  3. auto copy & paste in the mac terminal
    By louwang in forum OS X - Apps and Games
    Replies: 5
    Last Post: 12-19-2009, 11:37 PM
  4. script to auto-unmount volumes on restart/shutdown?
    By squeabs in forum OS X - Operating System
    Replies: 0
    Last Post: 03-26-2009, 06:43 PM
  5. Script to copy files
    By bennys in forum OS X - Operating System
    Replies: 0
    Last Post: 03-12-2007, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •