I do a lot of embedded software development. The microcontrollers have mini file systems that my programmer pushes new firmware onto the chip through.

Since I upgraded to Big Sur, I have been inundated with a significant number of Finder "Disk Not Ejected Properly" notifications every time I do the above.

Before Big Sur, these would vanish into Notification centre and I could clear them all. In Big Sur, I cannot.

I tried to record an Automator workflow to press the "close" button on the notifications, and this is fine until I try to run the workflow via Terminal where I get error:

The action “Watch Me Do” encountered an error: “This application must be allowed to control this computer using accessibility features, using the Security & Privacy preferences located in System Preferences, before using Watch Me Do”

I HAVE allowed these permissions, and tried executing with sudo, but no improvement. I then tried dragging the individual watch me do stages into its own stage to see the underlying AppleScript - as I am not so well versed with AppleScript, it didn't help me much.

There are a number of similar scripts online but they don't work with Big Sur from my testing,

Can anyone help me write an AppleScript that I can run via Terminal to help me dismiss these notifications?

They're driving me crazy and have to leave my Do Not Disturb on all day to hide this mess.

(1: to stress, these are not USB thumb drives or hard disks. These are microcontrollers so cannot be ejected due to the nature of firmware development)

enter image description here

  • 1
    Why not just eject the disks properly?
    – Tetsujin
    Jul 5 '21 at 16:35
  • 1
    @Tetsujin the devices aren’t disks like a HDD or USB flash drive. They’re microcontrollers that have embedded file systems - this is what the programmer looks for to push my firmware onto. There’s no concept of ejecting these as the filesystem vanishes after firmware is programmed Jul 5 '21 at 19:28

The example AppleScript code, shown below, was tested in Script Editor and as an executable shell script in Terminal, under macOS Big Sur with Language & Region settings in System Preferences set to English (US) — Primary and worked for me without issue1.

  • 1 Assumes necessary and appropriate settings in System Preferences > Security & Privacy > Privacy have been set/addressed as needed.

The following example AppleScript code saved as an executable shell script should do the trick. Note that limited testing was done and the code may need to be adjusted.


tell application "System Events"
    tell application process "NotificationCenter"
        repeat while exists (UI elements of scroll area 1 of window 1)
                perform (first action of group 1 of UI element 1 of ¬
                    scroll area 1 of windows where description is "Close")
            end try
            delay 1
        end repeat
    end tell
end tell


As coded, this should click the close button on all notifications until there are no notifications left. If you want to only target notifications with "DISK NOT EJECTED PROPERLY" then you'll need to modify the code to do so.

Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

  • After unexpected results, I learned that the way I was trying to run the AppleScript code was also incorrect. Subsequent attempts with the above code and by creating an executable script, I was able to close these notifications. Thank you very much! Jul 5 '21 at 21:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .