• 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 image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Eject image


  • Subject: Re: Eject image
  • From: Luther Fuller <email@hidden>
  • Date: Thu, 28 Feb 2013 13:43:36 -0600

So, I decided to write a script that would unmount image disks.
More complicated than I thought at first.

FIRST, run this …

on run
set imageInfo to (do shell script "hdiutil info -plist ")
tell application "System Events" to set InfoRecord to value of (make property list item with properties {text:imageInfo})
--
set newFilePath to ((path to desktop) as text) & "hdiutil-info.plist"
tell application "System Events"
make new property list item with properties {kind:record, value:InfoRecord}
make new property list file with properties {contents:the result, name:newFilePath}
end tell
end run

This will create the .plist file on your desktop. Open it with Xcode so you can refer to it in the next script.

Second, run this script …

on run
set imageInfo to (do shell script "hdiutil info -plist ")
tell application "System Events" to set InfoRecord to value of (make property list item with properties {text:imageInfo})
--
set mountPointList to {}
set imagesList to images of InfoRecord
repeat with imageItem in imagesList
set entitiesList to |system-entities| of imageItem
repeat with entityItem in entitiesList
try
|mount-point| of entityItem
set mountPointList to mountPointList & {the result}
end try
end repeat
end repeat
log mountPointList
beep
end run

You can verify that it is correctly identifying the disks. And you can compare the script with the contents of the .plist file in order to understand the script.

Now, all you have to do is replace log mountPointList with script which tells the Finder to eject the disks.
Here's a completed script that will eject every image disk.

on run
set imageInfo to (do shell script "hdiutil info -plist ")
tell application "System Events" to set InfoRecord to value of (make property list item with properties {text:imageInfo})
--
set mountPointList to {}
set imagesList to images of InfoRecord
repeat with imageItem in imagesList
set entitiesList to |system-entities| of imageItem
repeat with entityItem in entitiesList
try
|mount-point| of entityItem
set mountPointList to mountPointList & {the result}
end try
end repeat
end repeat


repeat with mountPoint in mountPointList -- very slooooow
(POSIX file mountPoint) as alias
tell application "Finder" to eject the result
end repeat
beep
end run

 _______________________________________________
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 image (From: Robert Poland <email@hidden>)
 >Re: Eject image (From: Christopher Stone <email@hidden>)
 >Re: Eject image (From: Luther Fuller <email@hidden>)

  • Prev by Date: Re: Eject image
  • Next by Date: Pages-inserted/generated page numbers throw off char indexing in body text
  • Previous by thread: Re: Eject image
  • Next by thread: Re: Eject image
  • Index(es):
    • Date
    • Thread