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

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

  • Unmount disk image at logout

    Account Preferences->Login items allows you to list disk images to mount on login, but these disk images do not get unmounted at logout - they can still be seen by other accounts.
    Is there any way to force the Login items disk images to be unmounted when an account logs out?

    Phill Hughes wrote:
    Fine with scripting, but if the users have to remember to click something before logging out then they just as well eject the disk images. A cron job would work, but it would be nice to just have it happen. Thanks for the suggestions.
    cron won't be good for this unless you want to run it every minute. I would use a logout hook
    http://support.apple.com/kb/HT2420?viewlocale=en_US
    so it's only executed on the logout. it can run an apple script along the following lines
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    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
    end tell</pre>
    this will unmount all externals and disk images when a user logs out.

  • 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.

  • 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.

  • 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.

  • Disk image not opening with disk image mounter...

    I downloaded a shareware program and for some reason it reset my dmg files to open with it instead of with the default normal program.
    I cannot find the "diskimagemounter" that is listed in the open with... option (used spotlight to find name). i can have it use the disk utility, but wouldn't that run the disk utility program in the front everytime i mounted an image?
    any help would b greatly appreciated.
    thanks,
    jason Kent

    Choose a .dmg file and then "Get Info" (command-i)
    Under "Open with" set to "DiskImageMounter" and select change all.
    fyi - the app itself resides in /system/library/coreservices.
    -mj
    [email protected]

  • 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.

  • 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.

  • Unable to create restore disk image with Disk Utility

    I've tried three times in order to create a restore image of the users' volume of my Powerbook. I followed exactly the procedure explained typing "man asr" in a terminal window. I booted the Powerbook in target disk mode while connected to my iMac G5 from which Disk utility was run. Every time the disk image creation failed with a log report like this:
    Creating Image “HOME_HD.dmg”
    Initializing...
    Copying...
    /Volumes/HOME_HD: Authentication error
    Initializing...
    Finishing...
    Initializing...
    Creating...
    Copying...
    could not access /Volumes/HOME_HD/./Users/delos/Music/iTunes/iTunes Music/David Bowie/The Best Of David Bowie 1974-1979/01 Sound And Vision.m4a - Input/output error
    Finishing...
    Unable to create “HOME_HD” - Input/output error.
    I don't know how my imported music could create such a problem to Disk utility, nevertheless I removed the incriminated song from the Music library but another one raised to be not accessible. Then I booted the powerbook from the supplied Tiger DVD too, and I got an error over the music file, something about an allocation that was 190 instead of 1, I got the volume repaired from Disk utility but the Disk image creation failed again without any hint because booting from DVD does not allow to save log file anywhere. Why on Earth I can't manage such a critical task as back up under Tiger while using Panther everything worked like a charm following the same procedure? Is anyone experiencing something similar?
    Greetings
    Gianmarco

    Hi Lee, thank you for your answer, indeed I've just read carefully your article few hours ago, while I googled the net to find some hints on my issue. I think that I've followed exactly the right procedure to make the back up image, and can't find what is wrong. Actually Disk utility Repair disk successfully repaired the allocation bit (whatever that means) of the music files but that wasn't enough to let the creation of the disk image. Quite odd that the music files where recognized as messed up by Disk utility only booting from Tiger DVD and not while the Powerbook was connected to an iMac running Tiger too.
    I'll do further investigation during weekend.
    Greetings
    Gianmarco

  • Create encrypted disk image with OS install disk utility.

    I thought to make a full backup of Macintosh HD, and followed instructions in /kb/ht1553.  However, every time I tried to creae an encrypted disk image, it barfed with "Failed - User interaction required". I assume it needed the encryption password, but for some reason was unable to display a prompt for this. Anyone know how to fix this?  Thanks, Stephen.

    Create an encrypted sparse disk image instead of from folder, mount it, and then drag & drop your files into ii.

  • I can't get rid of the "Install OS X" disk image...

    Several months ago (I think it was when upgrading from 10.6.2 to 10.6.3) I had trouble with two machines - my wife's MBA (Rev. A - 1.6 GHz, 2GB ram, 80 GB HDD), and my MBP, but our iMac did fine. Eventually I got both the MBA and MBP updated and they work fine. Since then I've updated the MBA so that it's running 10.6.4.
    Here's my problem: during the difficult software update somehow I was left with two (2!) "Install OS X" disk images on the MBA desktop. I cannot get rid of them no matter what I do. I've tried ejecting (and they eject - but then when you reboot the computer they come right back), I've tried using disk utility to erase them, I've tried numerous things but I can't get rid of the darn things.
    I'd given up because they weren't causing any harm. However, I've just realized I can't run TimeMachine because of the disk images - TimeMachine stops with an error message saying it can't back up two disks with the same name. I can't change the name or delete the disk images so I can't do backups.
    Any ideas on how to get rid of these silly things?

    OK, then open Disk Utility. Click on the main drive entry at the top of the sidebar list, then click on the Partition tab in the DU main window. You should see a window in which you have the three partitions displayed as rectangles one on top of the other. I'm assuming that in your case the largest rectangle is the uppermost one with the two mystery partitions at the bottom. Click in one of the smaller rectangles. You should see it become outlined in blue. Then click on the [-] Delete button. Repeat for the second small rectangle. You will now have a gray area below your OS X partition. Now click on the Apply button. It may take several minutes for the process to complete so be patient and wait until it's done. When it's finished you should see the topmost OS X partition and the remainder of the window is gray space. In the lower right corner of the OS X partition should be a sizing gadget that looks like a triangle. Use the mouse to drag the corner all the way to the bottom of the window. Click on the Apply button and wait for the process to be completed.
    This should restore your drive to it's original single volume state and get rid of the two mystery items.

  • Can't load disk image when doing first backup

    Hi
    I've had to erase my Time Capsule's Time Machine sparesebundle as it had a corruption. And now I am trying to do a first backup again.
    Unfortunately, I keep getting an error message telling me the machine can't create a disk image; I have no idea why. I have tried changing my computer name in case that makes a difference (but I don't see why as the previous name worked fine for a year or more).
    Since trying to start this new process, I have noticed that sometimes in the TM preference pane that the TC name is given a Time Capsule-1 as opposed to its normal name of Time Capsule.
    Below is the log captured from the TM widget.
    Starting standard backup
    Mounted network destination using URL: afp://graemeaustin@Time%20Capsule.afpovertcp.tcp.local/Time%20Capsule
    Backup destination mounted at path: /Volumes/Time Capsule-1
    Creating disk image /Volumes/Time Capsule-1/Austin MacBook_001f5bf6a447.sparsebundle
    2010-04-04 12:13:09.184 diskimages-helper[466:1603] Error loading /Library/Plug-ins/DiskImages/NUMPlugin.bundle/Contents/MacOS/NUMPlugin: dlopen(/Library/Plug-ins/DiskImages/NUMPlugin.bundle/Contents/MacOS/NUMPlugin, 262): no suitable image found. Did find:
    /Library/Plug-ins/DiskImages/NUMPlugin.bundle/Contents/MacOS/NUMPlugin: mach-o, but wrong architecture
    2010-04-04 12:13:09.186 diskimages-helper[466:1603] Cannot find function pointer VRPreviewCFPlugInFactory for factory 20D1C6B2-6A02-11D7-B5A6-000393D45566 in CFBundle/CFPlugIn 0x521da0 </Library/Plug-ins/DiskImages/NUMPlugin.bundle> (bundle, not loaded)
    2010-04-04 12:13:09.189 diskimages-helper[466:1603] Error loading /Library/Plug-ins/DiskImages/NUMPlugin.bundle/Contents/MacOS/NUMPlugin: dlopen(/Library/Plug-ins/DiskImages/NUMPlugin.bundle/Contents/MacOS/NUMPlugin, 262): no suitable image found. Did find:
    /Library/Plug-ins/DiskImages/NUMPlugin.bundle/Contents/MacOS/NUMPlugin: mach-o, but wrong architecture
    2010-04-04 12:13:09.191 diskimages-helper[466:1603] Cannot find function pointer VRPreviewCFPlugInFactory for factory 20D1C6B2-6A02-11D7-B5A6-000393D45566 in CFBundle/CFPlugIn 0x521da0 </Library/Plug-ins/DiskImages/NUMPlugin.bundle> (bundle, not loaded)
    Error 35 creating backup disk image
    Failed to create disk image
    Backup failed with error: 20
    Ejected Time Machine network volume.
    Any help is of course so very welcome.
    Thanks in advance
    Graeme

    I tried to start the backup again, after logging out and back in again (as I had done several times before), but this time the sparsebundle loaded ok and the backup started properly.
    So there's no need for anyone to spend any time on me.
    Graeme

Maybe you are looking for

  • Office 2013 local Click to Run deployment error

    I have downloaded the x32 version of Office2013 to a local deployment share, making use of the Office Deployment tools. The download succeeded. Share is read access for everyone. When launching the installer from the share, on a x64 Win7 client, the

  • Prompting for SAVE as the document with Digital signatures in 8 or above

    When i am doing digital signature on Adobe PDF 8 and above  , it is prompting to SAVE AS the document.I am accessing the PDF documents from my document management application and signing on that.So Save as wouldnot work for our case.It should save on

  • Smart form -Right Alignment is not coming properly

    Hi Folks, While Printing Smart form for Invoice ,using right aligned Paragraphs  texts are not coming properly.....but  using left aligned paragraphs text  are coming proporly....we want both left aligned and right aligned in same table ...for print

  • A few simple questions

    Hi, the company I work for will soon be doing some work with OS X server and in an effort to familiarise myself with the software I have set it up at my home on an old blue and white G3 (sadly the best hardware I have to spare right now). I would lik

  • MDM API - Identifying Workflows

    Hello All, I have written an application which gets launched when a  user clicks on the UWL subject line. This application recieves an MDM Workflow ID. Based on the Workflow ID recieved my application has to launch some different IViews. Is there any