How to Get a Power Cable Connected/Disconnected Alert on macOS

There are few tiny betrayals in modern life more annoying than thinking your MacBook is charging, only to discover later that the cable was loose, the USB-C dock got moody, or the cat performed a silent unplugging ceremony under your desk. macOS already shows battery information in the menu bar, but it does not always shout, sing, or throw confetti when your power cable is connected or disconnected.

The good news: you can create your own power cable connected/disconnected alert on macOS using built-in tools. The most reliable method is a small shell script that checks whether your Mac is drawing power from the adapter or the battery, then sends a notification when that state changes. Add a LaunchAgent, and the alert can run automatically after login without you babysitting Terminal like it owes you rent.

This guide explains how to build a practical macOS charging alert, how it works, how to customize the sound and message, and how to troubleshoot common issues. The steps are beginner-friendly, but detailed enough for power users who like their laptops obedient and their cables accountable.

Why Add a Power Cable Alert on macOS?

A power cable alert is useful when you want your Mac to immediately notify you when charging starts or stops. That sounds simple, but it can save real frustration in everyday situations.

For example, if you use a USB-C hub, external monitor, docking station, or MagSafe adapter, the connection may briefly drop when the cable shifts. If you work in clamshell mode with the lid closed, you may not notice the Mac switched to battery power. If your charger is plugged into a loose power strip, the menu bar icon may be too subtle to catch your attention. And if you often move between rooms, classrooms, offices, cafés, and couches, an audible alert can prevent the classic “Why am I at 7%?” tragedy.

macOS does a good job reporting battery status, power source, and charging behavior, but it does not provide a built-in setting that says, “Play a custom alert whenever the adapter is unplugged.” So we create one ourselves using tools already available on the Mac.

How macOS Detects Power Cable Status

Before building the alert, it helps to understand what the Mac actually reports. A MacBook can be in several power-related states:

  • AC Power: The Mac is connected to an adapter, dock, monitor, or power source.
  • Battery Power: The Mac is running from its internal battery.
  • Charging: The battery is actively gaining charge.
  • Not Charging: The Mac is connected to power, but charging is paused, limited, or not currently needed.

That last one matters. “Power adapter connected” and “battery charging” are not always the same thing. macOS may pause charging because of Optimized Battery Charging, battery health management, heat, a weak power source, or because the battery is already near full. In other words, your Mac can be plugged in while the battery says “Not Charging,” and that may be perfectly normal.

For a connected/disconnected alert, we care mainly about the power source. Is the Mac drawing from AC power, or did it switch to battery? The simplest built-in command for that is:

When plugged in, the output usually includes something like:

When unplugged, it usually says:

That one line is the foundation of our alert system. We will check it repeatedly, compare the current result with the previous result, and notify you only when it changes.

The Best Native Method: A Shell Script + macOS Notification

The most dependable approach is a small script that runs in the background. It uses pmset to read the power source, osascript to show a macOS notification, and optionally afplay to play a system sound.

This method has several advantages:

  • It uses tools included with macOS.
  • It does not require buying an app.
  • It works with MagSafe, USB-C chargers, docks, and many powered displays.
  • It can be customized easily.
  • It can start automatically at login with a LaunchAgent.

Step 1: Create a Folder for the Script

Open Terminal and create a Scripts folder if you do not already have one:

This keeps your alert script in a tidy place. A tidy script folder is not required by macOS, but it is required by sanity.

Step 2: Create the Power Cable Alert Script

Now create a new file:

Paste the following script:

Save the file by pressing Control + O, then Return. Exit nano with Control + X.

Step 3: Make the Script Executable

Run this command:

This gives macOS permission to run the script as a program.

Step 4: Test the Alert Manually

Run the script:

Now connect or disconnect your charger. Within about five seconds, you should see a notification. When connected, the script shows “Power Connected.” When disconnected, it shows “Power Disconnected.”

To stop the test, return to Terminal and press:

If the alert appears, congratulations. Your MacBook is now slightly more dramatic, which is exactly what we wanted.

Step 5: Let Notifications Appear on macOS

If the script runs but you do not see a banner, check your notification settings. Go to:

Look for Terminal, Script Editor, osascript, or another related app that appears after the first notification attempt. Make sure notifications are allowed and that the alert style is set to banners or alerts.

Also check Focus mode. If Do Not Disturb or another Focus is active, macOS may hide your notification. Your script might be working perfectly while Focus mode stands at the door wearing sunglasses and saying, “Not today.”

Step 6: Start the Alert Automatically with a LaunchAgent

Running the script manually is fine for testing, but not ideal for daily use. To make the alert start automatically when you log in, create a LaunchAgent.

First, create the LaunchAgents folder if needed:

Now create the LaunchAgent file:

Paste this:

Replace YOUR-USERNAME with your actual macOS short username. You can find it by running:

For example, if your username is alex, the script path should be:

Save the file, then load it:

To start it immediately, run:

Now unplug and reconnect the charger. The alert should run in the background automatically.

How to Stop or Remove the Alert

If you decide your Mac has become too chatty, unload the LaunchAgent:

To remove everything:

You can always reinstall it later. Unlike that one browser toolbar from 2009, this is easy to remove.

Customize the Notification Message and Sound

You can change the alert text inside the script. Look for these two lines:

Change the title, message, or sound name. macOS includes system sounds such as Glass, Basso, Ping, Pop, Hero, Funk, and Submarine. Availability may vary by macOS version, so test your favorite.

For a louder or more obvious sound, you can also use afplay. Add this inside the disconnected section:

For example:

This can be helpful if you miss banners but respond instantly to sound. Some of us are basically houseplants with inboxes.

Optional Method: Use terminal-notifier

If you want richer notifications from the command line, you can use terminal-notifier, a popular open-source utility available through Homebrew.

Install it with:

Then replace the AppleScript notification line with something like:

The native osascript method is enough for most users, but terminal-notifier can be useful if you already use command-line notification workflows. If you want the fewest dependencies, stay with the built-in AppleScript method.

Optional Method: Use Automator or Shortcuts

Automator and Shortcuts can run shell scripts on macOS, so they are useful if you prefer graphical tools. However, they are better for manually triggered workflows than for continuously watching the power cable state.

In Automator, you can create an application or workflow and add the “Run Shell Script” action. In Shortcuts, you can create a shortcut that runs a shell command. These tools are convenient for one-click checks, but a LaunchAgent is more appropriate for a background monitor that should always be running after login.

A simple Shortcuts-style command might be:

That can show your current power source, but it will not automatically monitor cable changes unless you combine it with a loop or external trigger. For this particular job, the script-and-LaunchAgent approach is cleaner.

Troubleshooting: Why Your macOS Power Alert Is Not Working

1. No Notification Appears

Check System Settings > Notifications. Allow notifications for Terminal, Script Editor, or the app responsible for displaying the alert. Also check Focus mode. If Focus is active, banners may be hidden.

2. The Script Works in Terminal but Not at Login

The most common cause is a wrong path in the LaunchAgent. Make sure the plist uses your full user path, such as:

Do not use ~/Scripts inside the plist. LaunchAgent files are picky. They like full paths, proper XML, and being treated like royalty.

3. You See “Not Charging” Even When Plugged In

This is usually not a problem for the alert. “Not Charging” can happen when macOS pauses charging to protect battery health, when Optimized Battery Charging is active, when the battery is already high, or when the power source is not strong enough. The script checks whether the Mac is drawing from AC Power or Battery Power, not whether the battery percentage is actively rising.

4. The Alert Triggers Late

The script checks every five seconds. If you want faster alerts, change:

to:

A shorter interval is more responsive but slightly less efficient. Checking every five seconds is a good balance for most users.

5. The Alert Fires Too Often

If your USB-C dock or monitor repeatedly drops and restores power, the script may notify you every time. That is not the script being dramatic; that is your hardware tattling on itself. Try a different cable, charger, dock port, wall outlet, or power strip.

Battery Health Tips While You Are Here

A power cable alert is helpful, but it is only part of good MacBook battery care. You should also keep an eye on the bigger picture.

  • Use a charger that provides enough wattage for your MacBook model.
  • Avoid letting the battery sit at 0% for long periods.
  • Keep the Mac away from extreme heat while charging.
  • Use Optimized Battery Charging if it fits your routine.
  • Check battery health in System Settings > Battery.
  • Inspect frayed cables, weak adapters, and unreliable docks.

Modern MacBooks are smart about charging. They may pause, delay, or manage charging automatically to reduce battery aging. So if your Mac says it is connected but not charging, do not panic immediately. Panic is best saved for spilled coffee, missing backups, and hearing a suspicious crunch after stepping near your laptop bag.

Security and Privacy Notes

This alert script does not read your personal files, track your activity, access the internet, or send data anywhere. It checks local power status using pmset and displays a local macOS notification. That makes it a lightweight solution compared with installing a full battery utility just for a cable alert.

Still, be careful when copying scripts from the web. Read the commands before running them. Avoid scripts that ask for administrator privileges unless you understand exactly why they need them. The method in this guide runs as your user account and does not require sudo.

Real-World Experience: What It Is Like to Use a Power Cable Alert on macOS

After using a power cable connected/disconnected alert on macOS, the biggest benefit is not the novelty. The novelty wears off after the third “Power Connected” banner. The real benefit is confidence. You stop wondering whether your Mac is actually charging. You know immediately.

This is especially useful with USB-C setups. A direct MagSafe connection is usually obvious because the cable snaps into place and many adapters have a visible indicator. USB-C, however, can be sneakier. A cable may look connected but not sit firmly. A dock may pass display signal but fail to provide power. A monitor may charge the laptop only after waking up. A cheap hub may behave like it has unresolved childhood issues. In those cases, the alert becomes a small but valuable safety net.

The disconnected alert is more important than the connected one. When the cable is plugged in, you often notice because the battery icon changes. When the cable disconnects, you may not see anything if you are focused on writing, editing video, running a long export, or presenting on an external display. The alert gives you a chance to fix the problem before the battery quietly drains in the background.

A five-second check interval feels right for most workflows. It is fast enough that you notice the cable change almost immediately, but not so aggressive that the script feels wasteful. If you are using the Mac on battery all day, the script simply keeps checking and stays quiet because the state has not changed. It only speaks when something happens.

One practical lesson: choose different sounds for connected and disconnected events. A pleasant sound like Glass works well for power connected. A lower or more serious sound like Basso works better for power disconnected. Your ears learn the difference quickly. After a while, you do not even need to read the notification. The sound alone tells you whether everything is fine or whether your charger just rage-quit.

Another useful adjustment is to make the disconnected message more specific. Instead of “Power Disconnected,” you might use “Charger unplugged save your work.” That wording is helpful if you often run battery-heavy tasks such as video editing, software builds, virtual machines, or browser sessions with enough tabs to qualify as a small nation.

The alert is also handy for shared workspaces. If someone accidentally unplugs your charger to borrow an outlet, you know right away. No awkward detective work. No passive-aggressive sticky note. Just a notification politely saying, “Your Mac is now running on battery power,” which is computer language for “Somebody touched your cable.”

For clamshell mode users, this setup can be a lifesaver. When a MacBook is closed and connected to an external monitor, keyboard, and mouse, the built-in screen is not visible. If the power connection drops, you may not notice until performance changes or the machine sleeps. A sound alert helps you catch the issue immediately, even when the MacBook itself is tucked away on a stand.

There are a few quirks. If your dock briefly disconnects during sleep or wake, you may get alerts when returning to your desk. If Focus mode is active, banners might not appear. If notification permissions change after a macOS update, you may need to re-enable them. These are minor annoyances, but they are worth knowing before blaming the script and giving it a stern talking-to.

The most satisfying part is that the solution is simple. You do not need a heavy app, a subscription, or a complicated automation platform. A few lines of shell script, one LaunchAgent, and macOS can notify you when the power cable state changes. It is the kind of small automation that makes a Mac feel more personal and more practical.

In daily use, the alert fades into the background until it matters. That is exactly what good automation should do. It should not demand attention all day. It should step forward at the right moment, say the useful thing, and then get out of the way. A power cable alert is not glamorous, but when it saves you from a dead battery during a meeting, upload, render, or writing session, it suddenly feels like the smartest little upgrade on your Mac.

Conclusion

Getting a power cable connected/disconnected alert on macOS is easier than it first appears. macOS already knows whether your Mac is drawing from AC power or battery power; you simply need a small script to watch for changes and display a notification. By combining pmset, AppleScript notifications, and a LaunchAgent, you can create a lightweight charging alert that starts automatically and works quietly in the background.

This setup is especially useful for MacBook users with USB-C docks, external monitors, shared outlets, travel chargers, or clamshell desk setups. It helps you catch accidental disconnects early, avoid surprise battery drain, and confirm that your charger is actually doing its job. Best of all, it uses native macOS tools and can be customized with your own alert messages and sounds.