multi-OS scripting.

Discussion in 'Mac Basics and Help' started by Howard Brazee, Jan 31, 2007.

  1. Howard Brazee macrumors 6502

    Howard Brazee

    Joined:
    Oct 24, 2006
    Location:
    Lafayette CO
    #1
    I'm a new Mac person - on my Windows machines, I run .BAT files to synchronize my data files across machines.

    Now I need to add a Mac to this process - what tool and documentation should I look into for this process?
     
  2. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #2
    OS X is Unix-based so supports shell scripts. It also has AppleScript, and you can create scripts using Script Editor. Another possibility is to use Automator to create scripts.

    For sync'ing across different computers, the Unix utility rsync is probably the most commonly used since it comes with OS X and all other *nix OSs, but it doesn't come with Windows - you need to install cygwin to get rsync. I use rsync to do a backup of my /Users directory daily at 9pm.

    If you gave an example of your BAT files, someone, maybe even me, could give advice on how to implement it using bash scripts or AppleScript.
     
  3. Howard Brazee thread starter macrumors 6502

    Howard Brazee

    Joined:
    Oct 24, 2006
    Location:
    Lafayette CO
    #3
    They are pretty basic:
    ======================
    @DIR Z: 2>NUL | FIND /I "DIR" >NUL
    @If ErrorLevel 1 echo "no Drive Z: found"
    @If not ErrorLevel 1 echo "drive Z: found"
    @If ErrorLevel 1 goto :Finale

    Xcopy "Z:*.*" "%USERPROFILE%\My Documents\*.*" /E /D /I /Y
    pause
    Xcopy "%USERPROFILE%\My Documents\*.*" "Z:*.*" /E /D /I /Y

    :Finale
    pause
    =================

    I have to set them up so that these Workgroup computers see the shared directories by drive letter.

    Obviously, I will have to adjust this to where the iMac documents are, and for how iMacs share folders.

    My wife's EasyShare camera moves photos to the default location. In our old Mac environment, we had lots of subfolders which we named and organized.

    Well, I got a iPod, and she got an iMac - and the iPod doesn't appear to be able to handle multiple layers of picture folders (although it apparently did copy the photos - just not organized my way (apple thinks its way is better than my way)) - and iPhoto didn't accept our organization, so it appears it will take a while to reorganize - even though the pictures are still in the subdirectories. So I will have to figure out a compromise way of storing the pictures on both locations.
     
  4. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #4
    You can mount a network drive on a Mac using Finder, command-k, enter smb://<path to drive>.

    This will show up in /Volumes on your hard drive, so a simple script to copy files over would look like:
    Code:
    #!/bin/sh
    
    if [ -d /Volumes/<mounted drive> ]; then
        echo "Drive found";
        rsync -avz --exclude '.DS_Store' ~/Documents/* /Volumes/<mounted drive>/Documents/.;
        rsync -avz /Volumes/<mounted drive>/Documents/* ~/Documents/.;
    else
        echo "Drive not found";
    fi;
    
    
    Save this to eg. backup.sh and change it to executable. Play about with it to get it how you want, although I wouldn't use any real data until it works (I didn't actually test the script).

    As for iPhoto, it's been a long time since I set it up, but I thought there was an option to keep the original directory structure? I don't mind letting iPhoto handle the file locations, but then I'm not sharing photos across Macs and Windows machines.
     
  5. Howard Brazee thread starter macrumors 6502

    Howard Brazee

    Joined:
    Oct 24, 2006
    Location:
    Lafayette CO
    #5
    I will save that script. I assume it's AppleScript, which I have not yet looked at. I don't know what a *.SH file is, and I don't know what AppleScript executables look like. But this will give me a head start.

    I also need to learn how to define this mounted drive - I'm assuming for now that I will replace /Volumes/<mounted drive> with /Volumes/Howard's Documents and Settings - or whatever name I see on the Mac desktop after I connect to that shared location. I will also need to figure out the syntax of wherever the documents are on the Mac (Maybe they aren't all the same place).

    Also - so far, I haven't yet gotten the Windows machines to see the Mac drives, only the reverse. When I get it working, can I run .BAT files from there to do the synchronization? (While I suspect the AppleScript will be more powerful - I have to kick my wife off the machine to use it from there - I'm still saving up for my own Mac).
     
  6. plinden macrumors 68040

    plinden

    Joined:
    Apr 8, 2004
    #6
    It's actually a Unix bash script. It would work also with a Linux machine.

    Well, that's an alternative I didn't think of - I was looking at it from the Mac side.. You can turn on Windows Sharing in the Mac's preferences (under the Sharing option). You can then map the Mac HD in Windows.
     

Share This Page