Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Question:

Question: MERGING two Scripts to Unmount disks except booting disk

How to merge this AppleScript:


------------------------

set volname to "MemoryFlashCard" -- # name of target volume

set p to (POSIX path of (volname & ":" as alias))'s text 1 thru -2

set sh to "diskutil umount " & quoted form of p & " &> /dev/null &"

do shell script sh

------------------------


that unmounts Memory Flash Cards like the

SanDisk Extreme 128 GB SDXC Class 10 UHS-1 Flash Memory Card 45MB/s SDSDX-128G-X46

http://www.amazon.com/SanDisk-Extreme-Class-Memory-SDSDX-128G-X46/dp/B00720TE1M


with this AppleScript that unmounts the internal Macintosh HD:


------------------------

set volname to "Macintosh HD" -- # name of target volume

set p to (POSIX path of (volname & ":" as alias))'s text 1 thru -2

set sh to "diskutil umount " & quoted form of p & " &> /dev/null &"

do shell script sh

------------------------


so that the MemoryFlashCard is unmounted FIRST, and then the Macintosh HD after rebooting or cold booting the Mac from an external disk?


Thanks.

Posted on

Reply
Question marked as Solved
Answer:
Answer:

Hello


The AppleScript script below will unmount every device node which is mounted at mount point in /Volumes. Not sure whether it is safe with RAID.


do shell script "for dev in $(mount | perl -lne 'print $1 if m%(^/dev/[^[:space:]]+) on /Volumes/.*%o')
do
     diskutil unmount $dev >/dev/null 2>&1 &
done"


Regards,

H

Posted on

Page content loaded

Jun 14, 2013 5:56 AM in response to ApMaX In response to ApMaX

I'm not being funny, but having followed a number of your posts and threads on this issue, I have to say it does seem like you're not trying to solve a particular problem you're having, but rather exploiting the knowledge of this forum's users to develop and distribute an App to others that will do something which you don't have any understanding yourself of how to do.


I might be wrong, I probably am, and I hope I am, but in case I'm not let me point out this:


this is a forum for troubleshooting problems, answered by fellow amateur enthusiasts, and not a free 'develop my app for me' service.

Jun 14, 2013 5:56 AM

Reply Helpful
Question marked as Solved

Jun 14, 2013 11:50 AM in response to ApMaX In response to ApMaX

Hello


The AppleScript script below will unmount every device node which is mounted at mount point in /Volumes. Not sure whether it is safe with RAID.


do shell script "for dev in $(mount | perl -lne 'print $1 if m%(^/dev/[^[:space:]]+) on /Volumes/.*%o')
do
     diskutil unmount $dev >/dev/null 2>&1 &
done"


Regards,

H

Jun 14, 2013 11:50 AM

Reply Helpful

Jun 14, 2013 2:56 PM in response to Hiroto In response to Hiroto

Wow! Great!


That worked beautifully with different Macs to unmount any disk (except the booting one, of course), including the internal Macintosh HD (when booting from external disk or other disk), USB Pendrives and Flash Memory Cards.


The unmounted disks show also in Disk Utility (dimmed)or using Mountain

http://appgineers.de/mountain

so that it is possible later on to mount them manually without having to unpug and plug the external disks.


You made my day after weeks for search for this tool!!!


Many thanks!

Jun 14, 2013 2:56 PM

Reply Helpful

Oct 8, 2015 3:45 PM in response to ApMaX In response to ApMaX

#!/bin/sh
# uuid4fstab.sh Generates UUID lines for /etc/fstab so only boot partition is mounted.
### === How to use ===
### Before running this shell script, mount all drives in os-x Disk Utility
### uuid4ftab.sh | grep ^UUID > 4stab.txt
### Then copy and paste contents of 4stab.txt to /etc/fstab
### See http://www.macissues.com/2014/08/27/how-to-hide-a-hard-drive-partition-on-your-mac/
### for how to edit /etc/fstab with "sudo vifs" and/or sudo nano -w /etc/fstab
# Note similar goal as "two Scripts to Unmount disks except booting disk" at
# https://discussions.apple.com/thread/5102909 which uses something like:
### for dev in $(mount | awk '/Volumes/{print $1}')
### do
### diskutil unmount $dev >/dev/null 2>&1
### done
Above script would need to run every login. But the changes in fstab survive a reboot.
# === If you have non-mountable partitions asking to be initialized ===
# For partitions tgat cannot be mounted in os-X (like ext4), then try this:
# (1) change first line to:
# for i in /dev/disk*s*
# (2) edit 4stab.txt to remove the boot partition mounted at / (and any other cruft).
for i in `mount | awk '/Volumes/{print $1}' `
do
/bin/echo -n $i
diskutil info $i | awk -F\: '/Vol/'
# http://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk
UUID=`diskutil info $i | awk '/UUID/{gsub(/[ \t]+$/, "", $3); print $3 }' `
# get the filesystem type from output of "mount"
FSTYPE=`mount | grep $i | awk '{print substr ($4, 2, length($4) -2) }' `
echo FSTYPE="$FSTYPE"
# Output a line suitable for /etc/fstab staring with "UUID="
echo "UUID=$UUID none $FSTYPE ro,noauto 0 0 # $i "
done

Oct 8, 2015 3:45 PM

Reply Helpful
User profile for user: ApMaX

Question: MERGING two Scripts to Unmount disks except booting disk