Script to unmount or eject disk images

Is there a way to unmount disk images wiuth an automator or applescript? I have such a script to eject all disks, but this won't unmount disk images. I would like something that unmounts everything, except of course the startup disk etc.

Andrew Gara wrote:
That works!
However, I still have the problem that it will only eject 1 of 2 or 2 of 3 or 3 of 4 etc. I always have to run the script again to eject the remaining disk or image.
It says: Applescript error Finder got an error. Can't get disk 3 (or whatever is remaining.)
I really appreciate your help btw.
this of course makes sense because once a disk is ejected it's not counted among the remaining disks. we should start ejecting from the last disk (see the script below). Also, as i found out, Finder's eject command in apple script doesn't unmount internal drives. At least it didn't for me. I' not sure what the story here is.
One can circumvent this by calling a shell script command.
Something along the following lines.
tell application "Finder"
set nmd to number of disks
--this ejects externals and disk images
if nmd > 1 then
repeat with i from 2 to nmd
eject disk (nmd - i + 2)
end repeat
end if
--this ejects internals except for the start up
set nmd to number of disks
if nmd > 1 then
repeat with i from 2 to nmd
do shell script "diskutil unmount /Volumes/\"" & (name of disk (nmd - i + 2)) & "\"> /dev/null &"
end repeat
end if
end tell
I tested it on my computer and it ejects 10 disks and disk images well so I think it should work ok most of the times but there are probably situations when it will fail. I'm not sufficiently motivated to refine it.

Similar Messages

  • Recieved lightroom and says "eject disk image" but will not open

    I am trying to put light room on my Macbook and when I click on the dmg file it downloads and then says " please eject disk image" dates March 6th, 2012. When I do this it prevents me from opening the file.  Can anyone help as I am new to Mac. 

    http://helpx.adobe.com/download-install.html

  • Eject Disk Image at logout with AppleScipt?

    Hello, I would like to know how to use AppleScript to write a script that automatically ejects a disk image whenever the user logs out of their account.
    This script would be the complementary inverse to a login item I have setup wherein a specific disk image is mounted upon login.
    Because the disk image to be unmounted will be the same one every time, a script that simply uses the path to the image to accomplish the task will be fine (as opposed to a script that would scan for and unmount any mounted images found).

    Check this one out.
    I found this on MacScripter. You should check out that site too, as there are a lot of applescripts there.
    -- Adjust these values to your own requirements:
    property initialInterval : 5 * minutes -- The initial time to wait before starting the checks to see if the app has quit.
    property checkInterval : 10 -- The time (in seconds) between checks after that.
    property appName : "My App" -- The name of the app to watch.
    property diskName : "My Disk" -- The name of the disk to eject.
    global justOpened
    on run
              set justOpened to true -- Tells the 'idle' handler that this script applet's just started running.
    end run
    on idle
              if (justOpened) then
      -- Reverse the flag for next time and ask for the next 'idle' to come after the intial wait period.
                        set justOpened to false
                        return initialInterval
              else
      -- Otherwise check if the application is (still) running.
                        tell application "System Events" to set appRunning to (application process appName exists)
                        if (appRunning) then
      -- If it is, request the next 'idle' to come after the specified check interval.
                                  return checkInterval
                        else
      -- Otherwise eject the disk (if it's mounted).
                                  tell application "Finder"
                                            if (disk diskName exists) then eject disk diskName
                                  end tell
      -- Issue the log out command. (There'll be a 1-minute count-down dialog).
                                  tell application "System Events" to log out
      -- Tell this stay-open script application to quit. (It will only do so on the next 'idle'.)
      quit
      -- Request the next 'idle' to come after the shortest possible time.
                                  return 1
                        end if
              end if
    end idle

  • Can't eject disk image from Finder in Mountain Lion

    I just got a new MacBook pro. I'm running Mountain Lion (10.8.2). Any time I try to unmount an external hard drive or eject a disk image from the Finder, nothing happens (either clicking the contextual eject icon or right-clicking). The items in question are not in use when I try to eject them. I'm only able to do so with Disk Utility. Any ideas? I've repaired disk permissions but the problem persists.

    I am having similar issues with my user account. It also is the same in Yosemite.
    Disc images, external hard drives etc dragged to trash (get eject icon) are simply ignored.
    Pressing Eject button in side bar of Finder are ignored.
    It seems to be a permission/account issue as:
    - using computer under a different account doesnt have this problem
    - transferring account over to another mac continues the problem on the new computer.
    Log file seems not to have any errors.

  • How to eject disk image without needing it to run a program

    When ever i install a program from the internet such as Skype an image appears on my desktop...when i eject it and open Skype it says i cannot use it because i need it.how do i get rid of the image and still be able to use the program?
    Thanks-

    The sequence usually goes something like this:
    1. Download the disk image or package.
    2. Open or Double-click the disk image.
    3. Install or Drag the application into the applications folder.
    4. Eject the disk image or package.
    5. Run the application from the applications folder, keeping it in the dock if you choose.
    I say this without knowing specifically how Skype works, but this is generally how programs install.
    Joe

  • Eject disk image

    I keep getting prompted to eject my disk image when I double click he .pkg file to install lightroom. Please help me rectify the problem!

    I get prompted this. I've tried to re-download but the it still doesn't work..

  • How to eject disk image Pro.sparsebundle

    My time capsule does not allow me to backup or select it as the disk, the error message is
    The disk image "Michael's MacBook Pro.sparsebundle" is in use. Try ejecting the disk image.
    What do I do?
    Thanks

    This is quite a complex "fix"
    Pull the power cord from the back of the Time Capsule
    Count to ten
    Plug the power cord back into the back of the Time Capsule
    Wait a few minutes and try another backup.

  • Can't eject disk image after install on Mac, get error message: The disk "Thunderbird" couldn't be ejected because "Thunderbird" is using it.

    this is an upgrade from previous to current version. seemed to have started around the time yosemite came out.

    I don't have a background image. I called Apple and they had no idea what that error number meant. I deleted preferences for FCPX still didn't work, then delted all preferences and set up a new user. It now works. Apple has no idea what is going on.

  • Cannot unmount any disk images

    Hey guys, I've a problem. I can't unmount all the disk images that I've mounted. The same thing with usb external drives.
    The only way to eject is going to utility disk and unmount the images frome there. It's really annoying... Anyone can help me? I'm not sure, but i think that the problem was due to of cocktail software.. I set all the default setting but the problem isn't solved...
    thanks for your help.

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of the test is to determine whether the problem is caused by third-party software that loads automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you boot, and again when you log in.
    Note: If FileVault is enabled, or if a firmware password is set, or if the boot volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to boot and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal boot may also be somewhat slow.
    The login screen appears even if you usually login automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, reboot as usual (not in safe mode) and verify that you still have the problem. Post the results of the test.

  • Application disk image won't eject off the desktop?

    Hi,
    Lately I've been having this problem with either Firefox or Safari and I download something and the dmg extracts and I'm left with the white casing shell where the app is housed and it won't eject. I can't eject it from finder but dumping it to the trash from finder took it off the sidebar. I can't get them off my desktop unless I restart my Mac.
    Why is this happening and how do I fix it? I'm using Leopard 10.5.2.
    S.

    Thanks to DeltaMac I figured out all the problems I was having with my Finder. I was missing a lot of options under my Finder tab like Empty Trash, Preferences, Quit etc. Also I had no option to right click and eject disk images or external hard drives.
    All you have to do is download Onyx here: http://www.versiontracker.com/dyn/moreinfo/macosx/20070
    Then open up Onyx and go to OnyX/Parameters/Finder
    put a check in the box next to Show Preferences item, Show Empty Trash, Show Quit item, and Show Eject item and whatever else you want. You have to do them each individually though and wait for the prompt. Then item log out and back in again and everything should be back to normal.
    S.

  • Time machine - "the backup disk image could not be mounted"

    SInce a few days, I am unable to backup via Time Machine.
    I always get the message:
    TIME MACHINE ERROR
    The backup disk image could not be mounted
    I use an Apple Time Capsule and still have more than enough free space on it.
    Use OS X 10.5.5
    Help.....
    Tks

    Rosy,
    *_"The Backup Disk Image Could Not Be Mounted" (Console - “Failed to mount disk image”)_*
    First, it is important to distinguish this error message from another, similar Time Machine error that states “The backup volume could not be mounted”. This is important as the causes and cures for these two errors can be very different.
    Consider each topic below separately. When one option does not resolve your issue, then move on the next one.
    *Unmount the Backup Disk Image* (TC)
    If, for some reason, you have manually mounted the Time Machine backup disk image (sparsebundle), or Time Machine failed to eject it after the previous backup, subsequent backups may fail. (Console - “Failed to mount disk image”… “Backup failed with error: 21”)
    Eject the backup disk image (white drive icon) by either clicking the little Eject icon to the right of the disk image in the Finders’ Sidebar, or Ctrl-Click the drive icon on the desktop and select “Eject” from the contextual menu. Now try backing up again or launching Time Machine to view previous backups.
    *“Disconnect All Users…”:*
    If your Time Machine backup drive (“Backup of Users Computer”) is mounted on your desktop or in the Sidebar of the Finder window. then Time Machine may think the drive is already in use. Alternatively, if the Time Capsule hard disk has been recently accessed by a Windows machine, it may not have fully relinquished control. Do the following:
    Open Airport Utility and select the Time Capsule on the left.
    Click “Manual Setup”.
    Select “Disks” at top of window.
    Click “Disconnect All Users…” at bottom of window.
    Close the Airport Utility.
    Now try Backing up again.
    “I got it resolved. Apparently it had to do with one of the files being open on the disk from the drive. I had browsed the disk with one of my windows boxes here and it must have left one of the folders "open". Anyway, I rebooted the TC and we are good to go now.”
    *Proper Computer Name* #
    Make sure your computer has a proper name. Go to System Preferences --> Sharing. Time Machine needs to differentiate your computer from others on your network (i.e. "Bills MacBook" or "Office iMac"). If the "Computer Name" field is blank, create a name. Realize that if this step is necessary, you will likely have to start the Time Machine backup process over again and do another full initial backup.
    According to this article, [http://support.apple.com/kb/TS1760], Time Machine may experience problems if your computer name includes certain characters. Make sure the computer name only includes ASCII characters from the following set.
    (0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)
    Once a change in the computer name occurs, you should stop and restart Sharing on the affected computer. Uncheck and then recheck Sharing in the Services list on the left.
    Let us know if any of the suggestions above resolves your issue.
    Cheers!

  • Time machine error: The backup disk image could not be mounted

    Time Machine worked OK for several months. Now I get this error every 10 minutes or so.
    I unplugged Time Machine capsule and "Change Disk" in Time Machine options.
    Nothing helps, I continue to get this error.
    I cannot Enter Time Machine either. "Connecting to Server, Connecting to backup" does not work.
    Help please because I will probably have to archive and reinstall Leopard. I need the backups,
    Christine

    Christ1ne,
    Before you reformat the disk, consider these causes of this error.
    *_"The Backup Disk Image Could Not Be Mounted" (Console - “Failed to mount disk image”)_*
    First, it is important to distinguish this error message from another, similar Time Machine error that states “The backup volume could not be mounted”. This is important as the causes and cures for these two errors can be very different.
    Consider each topic below separately. When one option does not resolve your issue, then move on the next one.
    *Unmount the Backup Disk Image* (TC)
    If, for some reason, you have manually mounted the Time Machine backup disk image (sparsebundle), or Time Machine failed to eject it after the previous backup, subsequent backups may fail. (Console - “Failed to mount disk image”… “Backup failed with error: 21”)
    Eject the backup disk image (white drive icon) by either clicking the little Eject icon to the right of the disk image in the Finders’ Sidebar, or Ctrl-Click the drive icon on the desktop and select “Eject” from the contextual menu. Now try backing up again or launching Time Machine to view previous backups.
    *“Disconnect All Users…”:*
    If your Time Machine backup drive (“Backup of Users Computer”) is mounted on your desktop or in the Sidebar of the Finder window. then Time Machine may think the drive is already in use. Alternatively, if the Time Capsule hard disk has been recently accessed by a Windows machine, it may not have fully relinquished control. Do the following:
    Open Airport Utility and select the Time Capsule on the left.
    Click “Manual Setup”.
    Select “Disks” at top of window.
    Click “Disconnect All Users…” at bottom of window.
    Close the Airport Utility.
    Now try Backing up again.
    One poster reported: “I got it resolved. Apparently it had to do with one of the files being open on the disk from the drive. I had browsed the disk with one of my windows boxes here and it must have left one of the folders "open". Anyway, I rebooted the TC and we are good to go now.”
    *Proper Computer Name* #
    Make sure your computer has a proper name. Go to System Preferences --> Sharing. Time Machine needs to differentiate your computer from others on your network (i.e. "Bills MacBook" or "Office iMac"). If the "Computer Name" field is blank, create a name. Realize that if this step is necessary, you will likely have to start the Time Machine backup process over again and do another full initial backup.
    According to this article, [http://support.apple.com/kb/TS1760], Time Machine may experience problems if your computer name includes certain characters. Make sure the computer name only includes ASCII characters from the following set.
    (0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)
    Once a change in the computer name occurs, you should stop and restart Sharing on the affected computer. Uncheck and then recheck Sharing in the Services list on the left.
    # Try removing the apostrophe from the disk images name (sparsebundle).
    *A Stalled .inProgress Files:* #
    It may be that the previous backup attempt was ungracefully interrupted leaving remains that Time Machine can’t deal with.
    Stop any current backup attempt. Choose “Stop Backing Up” from the Time Machine menu.
    Open the Time Machine Preferences and turn “OFF” Time Machine.
    Open your Time Machine drive.
    Open the folder labeled “Backups,backupdb”.
    Now open the folder containing backups of the computer in question.
    Are there any “.inProgress” files there. Delete them by dragging the file to the Trash. Or Ctrl-Click the file and select "Move to Trash" from the contextual menu. (Give this time as deleting a large file on an external disk can take a while.)
    Turn Time Machine back “ON”. Now try backing up again.
    NOTE: If the above procedure becomes impossible to perform, try accessing the disk image from another Mac. Some have discovered that attempting a repair from another computer succeeds where the original computer failed.
    Let us know if any of the suggestions above helped to resolve your issue.
    Cheers!

  • Disappearing Disk Images

    Okay, so because we've had consistent issues with using Application Manager to install the ID 8.0.1 update, (NOTE: This is not the problem I'm posting about), we install them manaually.
    In the situation I'm posting about, for whatever reason, the Illustrator updates didn't work either. No big deal, this is the only time I've seen that. So download ID 8.0.1, and Ill. 16.0.3 and 16.0.4.
    Mount all three disk images, and then apply the updates in this order:
    16.0.3
    16.0.4
    then ID 8.0.1
    When the ID installer finished, it not only unmounted its own disk image, but the other two as well. Since this is an adobe installer, I couldn't look to see what had specifically caused this. Since installing and updating CS6 is somewhat...time consuming, I'm not about to see if it's just Adobe update disk imaage that are unmounted by the ID 8.0.1 udpater or all disk images.
    Just thought someone on the ID team should take a look at the post install scripts in the installer and check to see how they're unmounting images.

    Thank you for the feedback Bynkii.

  • "Backup disk image could not be mounted"

    I have been using time capsule successfully for about 5 months. But now it has suddenly started returning a time machine error "the backup disk image could not be mounted".
    Anyone got any suggestions?

    towersfamily,
    *_"The Backup Disk Image Could Not Be Mounted" (Console - “Failed to mount disk image”)_*
    First, it is important to distinguish this error message from another, similar Time Machine error that states “The backup volume could not be mounted”. This is important as the causes and cures for these two errors can be very different.
    Consider each topic below separately. When one option does not resolve your issue, then move on the next one.
    *Unmount the Backup Disk Image* (TC)
    If, for some reason, you have manually mounted the Time Machine backup disk image (sparsebundle), or Time Machine failed to eject it after the previous backup, subsequent backups may fail. (Console - “Failed to mount disk image”… “Backup failed with error: 21”)
    Eject the backup disk image (white drive icon) by either clicking the little Eject icon to the right of the disk image in the Finders’ Sidebar, or Ctrl-Click the drive icon on the desktop and select “Eject” from the contextual menu. Now try backing up again or launching Time Machine to view previous backups.
    *“Disconnect All Users…”:*
    If your Time Machine backup drive (“Backup of Users Computer”) is mounted on your desktop or in the Sidebar of the Finder window. then Time Machine may think the drive is already in use. Alternatively, if the Time Capsule hard disk has been recently accessed by a Windows machine, it may not have fully relinquished control. Do the following:
    Open Airport Utility and select the Time Capsule on the left.
    Click “Manual Setup”.
    Select “Disks” at top of window.
    Click “Disconnect All Users…” at bottom of window.
    Close the Airport Utility.
    Now try Backing up again.
    One poster reported: “I got it resolved. Apparently it had to do with one of the files being open on the disk from the drive. I had browsed the disk with one of my windows boxes here and it must have left one of the folders "open". Anyway, I rebooted the TC and we are good to go now.”
    *Proper Computer Name* #
    Make sure your computer has a proper name. Go to System Preferences --> Sharing. Time Machine needs to differentiate your computer from others on your network (i.e. "Bills MacBook" or "Office iMac"). If the "Computer Name" field is blank, create a name. Realize that if this step is necessary, you will likely have to start the Time Machine backup process over again and do another full initial backup.
    According to this article, [http://support.apple.com/kb/TS1760], Time Machine may experience problems if your computer name includes certain characters. Make sure the computer name only includes ASCII characters from the following set.
    (0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)
    Once a change in the computer name occurs, you should stop and restart Sharing on the affected computer. Uncheck and then recheck Sharing in the Services list on the left.
    Let us know if any of the suggestions above helped to resolve your issue.
    Cheers!

  • Disk image not mounted

    I have had a host of problems since i installed a Time Capsule. The latest is that after reinstalling my system software -- another story -- I have not been able to make back-ups. The message I get is back up failed, disk image not mounted. What is this? On my time capsule there is a disk image of my hard drive on a dog eared page called a sparse bundle. I'm sure this is easy, but I'm stumped.

    huk730,
    Welcome to the Apple discussion!
    Consider the following causes of that error message. Also bear in mind that when you reinstall the system software, Time Machine cannot continue using the same backups as before and will start a fresh set of backups. [http://support.apple.com/kb/TS1338]
    *_"The Backup Disk Image Could Not Be Mounted" (Console - “Failed to mount disk image”)_*
    First, it is important to distinguish this error message from another, similar Time Machine error that states “The backup volume could not be mounted”. This is important as the causes and cures for these two errors can be very different.
    Consider each topic below separately. When one option does not resolve your issue, then move on the next one.
    *Unmount the Backup Disk Image* (TC)
    If, for some reason, you have manually mounted the Time Machine backup disk image (sparsebundle), or Time Machine failed to eject it after the previous backup, subsequent backups may fail. (Console - “Failed to mount disk image”… “Backup failed with error: 21”)
    Eject the backup disk image (white drive icon) by either clicking the little Eject icon to the right of the disk image in the Finders’ Sidebar, or Ctrl-Click the drive icon on the desktop and select “Eject” from the contextual menu. Now try backing up again or launching Time Machine to view previous backups.
    *“Disconnect All Users…”:*
    If your Time Machine backup drive (“Backup of Users Computer”) is mounted on your desktop or in the Sidebar of the Finder window. then Time Machine may think the drive is already in use. Alternatively, if the Time Capsule hard disk has been recently accessed by a Windows machine, it may not have fully relinquished control. Do the following:
    Open Airport Utility and select the Time Capsule on the left.
    Click “Manual Setup”.
    Select “Disks” at top of window.
    Click “Disconnect All Users…” at bottom of window.
    Close the Airport Utility.
    Now try Backing up again.
    “I got it resolved. Apparently it had to do with one of the files being open on the disk from the drive. I had browsed the disk with one of my windows boxes here and it must have left one of the folders "open". Anyway, I rebooted the TC and we are good to go now.”
    *Proper Computer Name* #
    Make sure your computer has a proper name. Go to System Preferences --> Sharing. Time Machine needs to differentiate your computer from others on your network (i.e. "Bills MacBook" or "Office iMac"). If the "Computer Name" field is blank, create a name. Realize that if this step is necessary, you will likely have to start the Time Machine backup process over again and do another full initial backup.
    According to this article, [http://support.apple.com/kb/TS1760], Time Machine may experience problems if your computer name includes certain characters. Make sure the computer name only includes ASCII characters from the following set.
    (0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)
    Once a change in the computer name occurs, you should stop and restart Sharing on the affected computer. Uncheck and then recheck Sharing in the Services list on the left.
    Let us know if any of the above was helpful.
    Cheers!
    Message was edited by: Glenn Carter

Maybe you are looking for