62

Is there any way to disable the "the disk was not ejected properly" message?

I use a KVM and need to switch between two systems and have a memory stick that is in the KVM. The problem is that it's very annoying to get the message every time I switch from one computer to the other. I know, I can unmount it (and probably should), but I switch all the time, so it's a inconvenience to unmount, and there is nothing sensitive on the memory stick.

hairboat
  • 2,903
  • 18
  • 51
  • 72
  • 5
    Sorry, I have no answer. However keep in mind, that message is to remind you that data is held in memory and not yet written to the disk. Which is particularly important when you switch often. – DerMike Jan 07 '11 at 14:01
  • 9
    I've done this a long time and I have never lost anything. I'm not saying it won't happen, but I'm willing to take the risk. – Sindre Sorhus Jan 07 '11 at 15:19
  • 2
    Okay, I have to ask: anyone know why we got three near-identical questions within 10 hours—this one, 6090, and 6108 (and yes, the latter two have been closed as dupes). – Dori Jan 08 '11 at 01:38
  • 1
    @Dori It's the time after Christmas, so new Macs or Cameras with SD Cards :) Although I would like to point out that my question specifically was asking about the Write Cache, which is what the warning is usually about (ignoring issue like Symlinks/open system files on the drive) – Michael Stum Jan 08 '11 at 07:08
  • 1
    I hear what you are saying, that you would rather take the chance on losing the memory stick, I just thought I would let you know that it does happen; I found this forum because I didn't eject my memory stick before disconnecting and wasn't able to access the 1.8gb worth of movies that I just took. Luckily Disk Utility was able to fix it, this time. –  Jan 08 '11 at 14:09
  • 1
    @cate,@chrisparker2000: I converted your answers to comments. I understand your positions, but the OP states in his question that he does not care about losing data. So in this case, the posts are really commentary and not answers to the question. – Robert S Ciaccio Jan 08 '11 at 14:11
  • also, see http://meta.apple.stackexchange.com/questions/246/non-answers-disguised-as-answers-and-non-questions-disguised-as-questions – Robert S Ciaccio Jan 08 '11 at 14:59
  • @chrisparker2000: I've never heard of a drive being physically destroyed by not ejecting it. Where are you getting this information? How does a memory stick become so "corrupt" that it can't be reformatted? – Robert S Ciaccio Jan 08 '11 at 20:04
  • 1
    @dermike EXCEPT ... the problem is ... There is literally zero risk of that happening most of the time: Apple currently pops up the mesage in ALL cases, including the ones where there have been zero writes since the disk was inserted. You can't corrupt data if you have no data! – Adam Sep 23 '15 at 07:33
  • @DerMike the message always appears, even if the disk (such as a locked SD card) is read-only and/or no changes were made. It doesn’t mean that the disk has unwritten data, it just means that it could have unwritten data. – anonymousaga Sep 05 '21 at 02:47
  • 3
    I have the same problem BUT when you program a CircuitPython device it automatically mounts as CIRCUITPY. When the device reset (a very common occurrence during development) Mac OS pops "Disk Not Ejected Properly". Once I has about forty of these I had to clear one at a time! – Prof Huster Mar 02 '22 at 18:00
  • Let me also not in the context of motivation and searchability of this thread, that hard-ejecting is almost inevitable for Arduino/CircuitPython development and I guess with bootloaders of several devices. This popup disrupts the most typical development workflow. – neverlastn Nov 12 '23 at 23:27
  • @ProfHuster see the answer below by Matt Sephton – Gorm Feb 18 '24 at 18:30

7 Answers7

25

updated new better method

As mentioned by Russel in comments:

sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.DiskArbitration.diskarbitrationd.plist DADisableEjectNotification -bool YES && sudo pkill diskarbitrationd
James
  • 398
  • Will it continue to be unloaded after restarting my Mac? – Sindre Sorhus Apr 23 '11 at 15:39
  • 1
    Unloading a launchctl plist persists across restart, so I believe so. That said, I hardly ever reboot, so haven't tested it yet! – James Apr 23 '11 at 19:15
  • 2
    (I rebooted, and it has persisted fine :) – James Apr 29 '11 at 10:27
  • 5
    That solution has a negative side effect: It will also hide those "xy-application would like access to your contacts" popups. To revert it: sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.UserNotificationCenter.plist –  Jul 02 '13 at 01:08
  • 12
    Yeah this is very dangerous. It will most likely stop you from getting notifications from the system. In 2011, notifications were not a big deal but they kind of are today in 2015. – ahmet alp balkan Feb 10 '15 at 01:32
  • Is there any recommended way to do this so that it doesn't persist? – Sam Holmes May 13 '17 at 10:43
  • 1
    I think it would be better if you just disable the USB device notification instead of disabling the entire notification ?! sudo rm /usr/libexec/USBAgent – BabyBoy Jun 04 '21 at 09:01
  • 1
    I don't have enough reputation to answer myself, hopefully this is helpful to someone: sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.DiskArbitration.diskarbitrationd.plist DADisableEjectNotification -bool YES && sudo pkill diskarbitrationd – Russell Hancox Apr 18 '22 at 15:54
  • 2
    For me (on Monterey), sudo pkill diskarbitrationd seems to kill it permanently, or at least make it so that no disks are mounted until I reboot.

    Using sudo launchctl kickstart -k system/com.apple.diskarbitrationd seems to not have this issue.

    – reitermarkus May 29 '22 at 03:11
  • 2
    Whilst this worked for me, it seems heavy handed. It also stopped certain syncing apps from functioning correctly as they no longer saw devices being mounted (one example: Playdate Simulator for loading games onto a device over USB). – Matt Sephton Sep 17 '22 at 15:12
  • 1
    As others have said, this solution has potentially serious downsides. It made my system unable to install .dmg files, nor could I run hdiutil at all (disk mounting issues). Here's how to revert it: https://apple.stackexchange.com/a/444019/90894 – kip2 Nov 22 '22 at 19:48
23

This applescript will close them for you. Paste it into Script Editor and then Save as an application. Then grant access to that application in (System Preferences > Security & Privacy > Accessibility) Then you can use an application like ControlPlane https://www.controlplaneapp.com/ to run the application on wake thus closing them all automatically! ** Note: You will need to grant Accessibility access to ControlPlane as well.

tell application "System Events"
tell process "NotificationCenter"
    set numwins to (count windows)
    repeat with i from numwins to 1 by -1
        tell window i
            set temp to value of static text 1
        end tell
        if temp contains "Disk Not Ejected Properly" then
            click button "Close" of window i
        end if
    end repeat
end tell
end tell

Update as of March 2023

@Zev Eisenberg: The above script does not work with macOS Ventura. Here is one that would:

tell application "System Events" to tell process "Notification Center"
    repeat with notificationWindow in windows
        tell notificationWindow
            set entireContents to entire contents
            repeat with content in reverse of entireContents -- iterate backwards so we close bottom notifications first, if that matters
                if class of content is group then
                    set groupStaticTexts to static texts of content
                    repeat with staticText in groupStaticTexts
                        set foundText to false
                        if value of staticText is equal to "Disk Not Ejected Properly" then
                            set foundText to true
                            exit repeat
                        end if -- text is the text we want to find
                    end repeat -- staticTexts in group
                if foundText then
                    -- We'd like to look for buttons in the group called "Close", but recent macOS versions hide the Close button until you hover over the notification, and there's apparently no way to hover in AppleScript. Instead, we inspect the actions of the group, and look for the one called "Close".
                    -- actions trick via https://github.com/Ptujec/LaunchBar/blob/master/Notifications/Dismiss%20all%20notifications.lbaction/Contents/Scripts/default.applescript via https://www.reddit.com/r/applescript/comments/ycilyr/comment/iu5m3q5/?utm_source=reddit&utm_medium=web2x&context=3

                    repeat with groupAction in actions of content
                        if description of groupAction is equal to "Close" then
                            perform groupAction
                            exit repeat
                        end if
                    end repeat
                end if
            end if -- if class of content is group
        end repeat -- entire contents of window
    end tell -- notificationWindow
end repeat

end tell

Alper
  • 3,936
OZbg
  • 231
  • 1
    Beautiful, I prefer this to completely disabling Notification Center. – NetOperator Wibby Apr 12 '18 at 15:11
  • Thanks. On Catalina I added a workflow in Automator, then selected AppleScript from the list of possible actions and pasted in your script and it worked, though I had to run it multiple times. – Rocket Garden Sep 26 '20 at 12:34
  • thank you so much. I can go to bed tonight feeling like this world is a better place than it was at the start of the day. – Sridhar Sarnobat May 14 '21 at 03:28
  • Any alternative to ControlPane now that it’s kind of old and not maintained anymore? – anonymousaga Sep 05 '21 at 03:05
  • 2
    This one doesn't work anymore (tested with OS 12.4) – RobKohr Aug 02 '22 at 13:50
  • does not work with Ventura (13.2.1) – akira Feb 17 '23 at 06:10
  • I'm using Ventura 13.2.1 also, and it comes back with error: System Events got an error: Can’t get static text "Eject “AUDIO-VIDEO” before disconnecting or turning it off." of group 35 of UI element 1 of scroll area 1 of group 1 of window "Notification Center" of application process "NotificationCenter".. It appears to be grabbing text from the notification message not the just the title. – inspirednz Mar 13 '23 at 22:11
10

Certainly not an elegant answer but, you can disable UserNotificationCenter.app found in /system/library/coreservices - replace it with another app or file with the same name. It will stop any warnings popping up (including that your drive is full) so watch out for that, but in my experience it does what you are looking for.

I actually did this to my mac a long time ago, and forgot about it until you asked you question. Credit to Macpadawon at http://macosx.com/forums/mac-os-x-system-mac-software/297194-disable-device-removal-message.html for the answer - same place I found my answer a couple of years back.

Ciaocibai
  • 1,073
  • Wow. Nice catch. I certainly wouldn't do this to my own system, but it's nice to know it can be done. I suppose the app could be replaced with an empty file. – Harv Jan 18 '11 at 01:42
  • I've done it on three different macs with no issues, although most of the time I just unmount things as well. – Ciaocibai Jan 18 '11 at 22:23
  • 2
    At least you did not notice any issues, right? Sorry, couldn't resist. :-) – DerMike Jan 21 '11 at 11:20
  • Link is dead. Also replacing system apps is not advisable. – Matt Sephton Sep 17 '22 at 15:10
5

This can be done by changing the type of this system notification from alert to banner. Sadly, it can't be done using the GUI but can be done with a script. gist

The crux of the script is to clear the alert bit & ~0b00010000 and set the banner and modified bits | 0b01001000 of _SYSTEM_CENTER_:com.apple.DiskArbitration.DiskArbitrationAgent in file ~/Library/Preferences/com.apple.ncprefs.plist

After this modification, the notifications will still appear but will disappear after a few seconds of their own accord.

Taken from: adafruit blog and tested successfully on macOS 12.6 Monterey.

Matt Sephton
  • 5,068
3

Works with macOS Big Sur

This AppleScript dismisses all notifications about the disk not being ejected properly.

tell application "System Events"
    tell process "Notification Center"
        set group_index to 1
        repeat
            try
                set the_window to group group_index of UI element 1 of scroll area 1 of window "Notification Center"
                set notification to value of static text of the_window
                set notification_title to item 1 of notification
                if notification_title = "DISK NOT EJECTED PROPERLY" then
                    set the_actions to actions of the_window
                    repeat with the_action in the_actions
                        if description of the_action is "Close" then
                            tell the_window
                                perform the_action
                            end tell
                        end if
                    end repeat
                    # Wait for the notification to disappear so that the indexes of the remaining notifications are updated accordingly.
                    delay 0.25
                    # Do not increment `group_index` because all remaining notifications have their index decremented by 1 since this notification was dismissed. We do not need to worry about the notifications before the one just dismissed because we already know that they are not notifications about disk ejection.
                else
                    # This is not a disk ejection notification, so skip it and look at the next notification.
                    set group_index to group_index + 1
                end if
            on error error_message
                # There are no more notifications to process.
                exit repeat
            end try
        end repeat
    end tell
end tell

You can run this AppleScript every 10 seconds with the launchd PLIST below. Be sure to modify it to work with your own setup. Then place the PLIST in ~/Library/LaunchAgents and run launchctl load ~/Library/LaunchAgents/file.plist (replacing file.plist with the name of the file) in Terminal.

What's really cool about launchd is that if a job does not run because the computer is asleep (e.g., when your laptop is closed), launchd will run the job as soon as the computer wakes up again (and if the job was supposed to run multiple times while the computer was asleep, the multiple runs will be coalesced into one run upon wakeup). This is really useful when unplugging a closed laptop from a home dock with a hard drive attached and then using the laptop on-the-go.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.YourName.DismissNotifications</string>
    <key>ProgramArguments</key>
    <array>
      <string>osascript</string>
      <string>/path/to/script</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>10</integer>
  </dict>
</plist>
-4

UPDATE!

OMG! QuantumG is a genius! Here is a hack (and I mean a real life hack) for disabling just this annoying message and leaving the rest of the notification system intact...

http://quantumg.blogspot.com/2015/04/disabling-os-x-device-removal-warnings.html

Warning: This is a pro-tip and not for the faint of heart! It requires hacking your Mac OSX system files and could result in you breaking your Mac.

Edited for clarity.

The issue with flash drives or other USB drives is this; whenever you write data to a drive... ANY drive on your system, the data is first written to a buffer in memory. Later, when the computer gets around to it, it will flush the buffers to the device (hard drive, SSD, or any USB device). That may be instantaneous (at least to us mere mortals) or it may take a few seconds. The possible delay means that if you yank a USB device before the buffers have flushed you may end up with a corrupted drive, or a set of corrupted files on the drive.

If you only read from a device, then there is NO NEED to flush the write buffers before you yank to your heart's content because they are empty and don't need to be flushed to the device.

So... The annoying MAC OS X warning is most probably NOT relevant. It is only important to do so if you have recently written to the device, and haven't given it enough time to flush the buffers (a few seconds, max). It is NEVER necessary to wait for the buffers to flush if you are only reading from the USB device.

Therefore Apple NEEDS to provide a way to disable individual messages for power users. Don't treat everyone as a n00b who can't be relied on to know how their computer works.

And to those who complain that I'm wrong, and there is a way to disable the messages by disabling the ENTIRE NOTIFICATION SUBSYSTEM are just plain wrong. Disabling the entire notification subsystem isn't an acceptable solution, just as removing the battery from your cell phone is NOT an acceptable solution to receiving too many telemarketing calls. The notification subsystem is important and shouldn't be disabled just because the OP finds one of the many myriad of messages to be annoying.

This is a problem that can only be adequately solved by Apple providing a way for users to opt out of specific messages.

  • 2
    So, I'm not sure this ramble really qualifies as an answer to the question... however an answer was already provided that does exactly what you are rambling can't be done - the messages can be disabled. However, as this does not attempt to provide any answer to the question, I'm going to flag this for deletion. – Charlie74 Jan 04 '16 at 23:54
  • @Charlie74 It's an attempt to make a point, so I'm not deleting it. I will edit out the vague chit chat towards the end. If OP wants to be clear, feel free to provide a positive explanation of why OS X is POSIX certified - https://en.wikipedia.org/wiki/POSIX#POSIX-certified and not POSIX-based. – bmike Jan 12 '16 at 17:35
  • @Charlie74 I clarified my answer, but to defend myself I never said it couldn't be done. I merely suggested that disabling the notification subsystem in order to stop one of the maybe hundreds of issues of which your mac may need to notify you, isn't an acceptable solution. It's only slightly better than "Stop using your Mac and the silly message won't bother you anymore".

    Only Apple can offer an acceptable solution, and they haven't yet.

    – Phillip H. Blanton Oct 29 '18 at 22:49
  • This approach does not work due to binaries needing to be signed. Disabling code signing would be worse than disabling the notification system. – Edward Anderson Nov 29 '18 at 12:35
  • I agree with Edward. So there is still NOT A VIABLE SOLUTION. – Phillip H. Blanton Mar 01 '19 at 20:45
-4

your answer is here. Just replace a file with the one mentioned at the end of this article and jobs done. Nothing has changed in Sierra or High Sierra.

Disabling OS-X Device Removal Warnings In Yosemite