• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Eject Bootable Clone
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Eject Bootable Clone


  • Subject: Re: Eject Bootable Clone
  • From: Gil Dawson <email@hidden>
  • Date: Wed, 16 Jul 2014 11:16:58 -0700

Thanks, guys. 

This is what I came up with...


--Eject Bootable Clone
--
-- Ejects a list of particularly-named disks whenever one mounts
--
-- Folder Action: to be
--    Stored in /Library/Scripts/Folder Action Scripts
--    Attached to the folder named /Volumes
--

property EjectableDiskNames : {"Orange Clone"}

on adding folder items to theVolumesFolder after receiving theseItems


tell application "Finder"


repeat with aDisktoEject in EjectableDiskNames
if exists (disk aDisktoEject) then
display dialog "Disk \"" & aDisktoEject & "\" mounted." & return & ¬
"If you do nothing, it will be ejected in a few seconds." buttons {"Keep it mounted.", "Eject it now."} ¬
default button ¬
"Eject it now." giving up after 5
set theResult to the result
if (gave up of theResult) ¬
or (button returned of theResult is "Eject it now.") then
display dialog "Ejecting disk \"" & aDisktoEject & ¬
"\" now." giving up after 2
eject (every disk whose name is aDisktoEject) -- Thanks, Phil
else
display dialog "Leaving disk \"" & aDisktoEject & ¬
"\" mounted." giving up after 2
end if
end if
end repeat
end tell
end adding folder items to



...and its companion...


--Mount Bootable Clone
--
-- Mounts a list of disks (by disk name) 
--  that are plugged in, but not mounted
--   because they have been ejected


property zero : 0
property one : 1
property nullstring : ""

property EjectableDiskNames : {"Orange Clone"}

repeat with diskName in EjectableDiskNames
tell application "Finder"
if disk diskName exists then
display dialog "Disk \"" & diskName & "\" is already mounted."
else
do shell script "diskutil mountDisk " & my devName(diskName)
end if
end tell
end repeat

on devName(diskName)
--Converts a Disk Name to a (Unix) Device Name
-- even if the disk is (plugged in but) not mounted
-- for use with "diskutil mountDisk " & devName(DiskName)
set diskutilReport to do shell script "diskutil list"
(* e.g.:
diskutilReport=/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *320.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS MBProHD                 319.7 GB   disk0s2
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *320.1 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS bu MBProHD 320GB        319.7 GB   disk1s2
/dev/disk2
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk2
   1:                        EFI                         209.7 MB   disk2s1
   2:                  Apple_HFS Orange Clone            999.9 GB   disk2s2
/dev/disk3
 ...etc.
 *)
set DiskNNameBeginsAtch to offset of diskName in diskutilReport -- "Atch" = At character (number)
if DiskNNameBeginsAtch is zero then
error diskName & " not found in diskutil list."
else
set DeviceNNameMightBeginAtch to DiskNNameBeginsAtch - one
repeat while DeviceNNameMightBeginAtch is greater than zero
set testDevN to ¬
(characters DeviceNNameMightBeginAtch through (DeviceNNameMightBeginAtch + 8) of diskutilReport) as string
if testDevN = "/dev/disk" then
return testDevN & character (DeviceNNameMightBeginAtch + 9) of diskutilReport
end if
set DeviceNNameMightBeginAtch to DeviceNNameMightBeginAtch - one
end repeat
end if
error "/dev/diskn not found in diskutil list."
end devName

Thanks again, guys.

What a great group to work with!

--Gil
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Eject Bootable Clone (From: Gil Dawson <email@hidden>)
 >Re: Eject Bootable Clone (From: Paul Fidler <email@hidden>)
 >Re: Eject Bootable Clone (From: Gil Dawson <email@hidden>)

  • Prev by Date: Xcode iOS Profiles
  • Next by Date: Setting Password on PDFs
  • Previous by thread: Re: Eject Bootable Clone
  • Next by thread: Inconsistent results with "do shell script"
  • Index(es):
    • Date
    • Thread