Mount drive using applescript

Discussion in 'Mac Programming' started by LERsince1991, Nov 11, 2014.

  1. LERsince1991 macrumors 65816

    Jul 24, 2008

    I am trying to set up my drives for an automated backup workflow using Carbon Copy Cloner.

    I didn't want the cloned drives mounted all the time - just when they are to be backed up.

    I edited the fstab file through terminal to noauto mount the backup drives on boot.

    I set up some small scripts to mount a drive.
    Set these to launch from iCal 15 mins before CCC clones it.
    Then once the clone is complete CCC also unmounts that drive before moving onto the next clone job.

    The Problem
    The issue I have is that the script I am using to mount the drive is referring to the Disk Identifier of each drive which is apparently changing when I reboot, or unplug and replug the drives in a different usb port - I'm on a macbook.

    The script is:
    do shell script "diskutil mount /dev/disk4s2"
    The disk identifier is obtained from the info in disk utility and is correct at that time as I have tested it and it works. - but after reboot etc, the DI has changed.

    The solution
    How can I modify the script to mount using the disk UUI (UUID) instead which is unique and always constant.

    Alternatively how can I set the Disk Identifier of these drives to always mount to a specific number which is reserved for that drive only?
  2. chown33 macrumors 604

    Aug 9, 2009
    descending into the Maelström
    What OS version is this for?

    The man page for diskutil says this about how to identify disks:
    A device parameter to any of the above commands (except where explicitly required otherwise) is usually any of the following:

    • The disk identifier (see below). Any entry of the form of disk*, e.g. disk1s9.

    • The device node entry containing the disk identifier. Any entry of the form of /dev/disk*,
    e.g. /dev/disk2.

    • The volume mount point. Any entry of the form of /Volumes/*, e.g. /Volumes/Untitled.

    • The Universally Unique Identifier or UUID. Any entry of the form of e.g.
    So anywhere you would give an identifier like disk4s2 you can give the UUID instead. Given this principle, which you will need to test and confirm, try the following.

    1. Determine the UUID of the disk. To do this, you'll need to manually mount it and determine its disk identifier. So mount the disk, then use this command in Terminal:
    diskutil list
    2. Take note of the disk identifier for the desired disk in the output. Let's say it's disk4s2 for now. You then use this command in Terminal:
    diskutil info disk4s2 | grep -i uuid
    3. The above command should output a line that lists the volume UUID. You can select, copy, and paste it from the Terminal window.

    4. To test that the UUID is correct, use this command in Terminal:
    diskutil info YOUR_UUID_HERE
    The output of this command should be a lengthy list of info about the disk volume. If so, confirm it's the disk volume you want to use.
    As noted in step 3, don't retype the UUID, simply select it using the mouse, cmd-C, then paste (cmd-V) in the Terminal window.

    5. Finally, edit your script and replace the /dev/diskwhatever with the entire UUID. Test the script by unmounting the volume and seeing if it works.
  3. Alrescha macrumors 68020

    Jan 1, 2008
  4. LERsince1991 thread starter macrumors 65816

    Jul 24, 2008
    Thanks both, I didn't realise CCC does this anyway, but I did try it and it didn't seem to mount it when it was scheduled to clone - I will try again.

    Anyway, the scripts still useful as I have added shortcuts to a folder so I can mount them quicker rather than using disk utility in future when I need access.


Share This Page