How to Uninstall TeamViewer on macOS Using a Script

Removing software from macOS systems can sometimes be more complicated than dragging an app to the Trash. Applications like TeamViewer install background services, launch daemons, and support files that must be properly removed to ensure system stability and security.

For IT professionals and Managed Service Providers (MSPs), automating this process can save significant time across fleets of machines. This post explores a shell script designed specifically to uninstall TeamViewer on macOS systems quickly, thoroughly, and reliably.

Background

TeamViewer is widely used for remote access and support, but in enterprise environments there are often policies requiring its removal once a project ends or when a different remote support solution is adopted. Manual uninstallation is error-prone and time-consuming, particularly when managing dozens or hundreds of endpoints. A shell script to uninstall TeamViewer on macOS provides IT teams with a repeatable, automated process that ensures consistency and reduces the chance of leaving residual files behind.

This script is especially valuable for MSPs who manage environments remotely through platforms like NinjaOne, where automation scripts can be executed across multiple client devices with minimal intervention.

The Script

#!/usr/bin/env bash
#
# Description: Uninstalls TeamViewer.
# By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
# Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
# Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
# Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
# Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
# Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
# Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
# EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#
# Example: (No Parameters)
#
# Verifying that TeamViewer is still installed.
# Removing TeamViewer using '"/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/UninstallTeamViewer" --force'
# Uninstalling...
# Done.
# Verifying that TeamViewer has been removed.
# TeamViewer has been successfully removed.
#
# Version: 1.0
# Release Notes: Initial Release

# Function to wait for the TeamViewer process to stop, with a timeout of 5 minutes.
waitForTeamViewer() {
  # Set timeout to 5 minutes from now.
  timeout=$(date -v+5M "+%s")

  # Check if the TeamViewer process is running.
  if pgrep -ifl "TeamViewer" 1>/dev/null; then
    echo "Waiting for the TeamViewer process to stop."
  fi

  # Loop until the TeamViewer process stops or the timeout is reached.
  while pgrep -ifl "TeamViewer" 1>/dev/null; do
    if [[ $(date "+%s") -ge "$timeout" ]]; then
      echo "[Warning] The five minute timeout has been reached."
      break
    fi

    # Wait briefly before checking again.
    sleep 0.1
  done
}

# Function to print an error message and exit with a specified return code.
die() {
  local _ret="${2:-1}"
  echo "$1" >&2
  exit "${_ret}"
}

echo " "

# Initialize the exit code variable if not already set.
if [[ -z "$exitCode" ]]; then
  exitCode=0
fi

# Ensure the script is run with root permissions.
if [[ $(id -u) -ne 0 ]]; then
  _PRINT_HELP=no die "[Error] This script must be run with root permissions. Try running it with sudo or as the system/root user." 1
fi

echo "Verifying that TeamViewer is still installed."

# Check if the TeamViewer uninstaller is available using `mdfind`.
if mdfindResult=$(mdfind kind:application "TeamViewer" 2>/dev/null | grep -v '^$'); then
  teamViewerUninstaller=$(echo "$mdfindResult" | grep "TeamViewerUninstaller")
  teamViewerInstalled="true"
fi

# Check if the TeamViewer application directory exists.
if [[ -d "/Applications/TeamViewer.app" ]]; then
  teamViewerInstalled="true"
fi

# Check if the specific uninstaller path still exists; if so, exit with an error.
if [[ -f "/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/UninstallTeamViewer" ]]; then
  teamViewerUninstaller="/Library/Application Support/TeamViewer/TeamViewerUninstaller.app"
  teamViewerInstalled="true"
fi

# If TeamViewer is not installed, check for the QuickSupport tool and exit with an error.
if [[ "$teamViewerInstalled" != "true" ]]; then
  if pgrep -ifl "TeamViewer" 1>/dev/null; then
    echo "[Alert] The TeamViewer QuickSupport tool was detected. The QuickSupport tool is not installed on the system because it is a portable app."
  fi
  _PRINT_HELP=no die "[Error] TeamViewer is not installed on this system." 1
fi

# Attempt to uninstall TeamViewer using the uninstaller(s) found by `mdfind`.
if [[ -n "$teamViewerUninstaller" ]]; then
  while IFS= read -r uninstaller; do
    echo "Removing TeamViewer using '\"$uninstaller/Contents/Helpers/UninstallTeamViewer\" --force'"

    # Run the uninstaller with the `--force` option.
    if ! "$uninstaller/Contents/Helpers/UninstallTeamViewer" --force; then
      _PRINT_HELP=no die "[Error] Failed to uninstall TeamViewer." 1
    fi

    # Wait for the TeamViewer process to stop.
    waitForTeamViewer

    # Check if the uninstaller is still present; if not, break the loop.
    if ! mdfind kind:application "TeamViewer" 2>/dev/null | grep "TeamViewerUninstaller" 1>/dev/null; then
      break
    fi
  done <<< "$teamViewerUninstaller"

  uninstallAttempted="true"
fi

# Attempt to uninstall TeamViewer using a specific uninstaller path.
if [[ -f "/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/UninstallTeamViewer" ]]; then
  echo "Removing TeamViewer using '\"/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/UninstallTeamViewer\" --force'"

  # Run the uninstaller with the `--force` option.
  if ! "/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/UninstallTeamViewer" --force; then
    _PRINT_HELP=no die "[Error] Failed to uninstall TeamViewer." 1
  fi

  # Wait for the TeamViewer process to stop.
  waitForTeamViewer

  uninstallAttempted="true"
fi

# If no uninstallation attempt was made, exit with an error.
if [[ "$uninstallAttempted" != "true" ]]; then
  _PRINT_HELP=no die "[Error] Failed to find the TeamViewer uninstaller." 1
fi

echo "Verifying that TeamViewer has been removed."

# Check if the app is still present; if so, exit with an error.
if foundApplications=$(mdfind kind:application "TeamViewer" 2>/dev/null); then
  while IFS= read -r application; do
    if [[ -f "$application" || -d "$application" ]]; then
      _PRINT_HELP=no die "[Error] Failed to uninstall TeamViewer." 1
    fi
  done <<< "$foundApplications"
fi

# Check if the app is still present; if so, exit with an error.
if [[ -d "/Applications/TeamViewer.app" ]]; then
  _PRINT_HELP=no die "[Error] Failed to uninstall TeamViewer." 1
fi

# Check if the specific uninstaller path still exists; if so, exit with an error.
if [[ -f "/Library/Application Support/TeamViewer/TeamViewerUninstaller.app/Contents/Helpers/UninstallTeamViewer" ]]; then
  _PRINT_HELP=no die "[Error] Failed to uninstall TeamViewer." 1
fi

echo "TeamViewer has been successfully removed."

# Exit the script with the specified exit code.
exit "$exitCode"

 

Access 300+ scripts in the NinjaOne Dojo

Get Access

Detailed Breakdown

The script follows a structured flow to ensure a clean uninstallation:

  1. Permission Check

    • It verifies the script is run with root privileges. Without elevated permissions, the script exits immediately since uninstalling system-level apps requires administrative access.
  2. Detection Phase

    • It searches for TeamViewer using mdfind (Spotlight index) and direct path checks (/Applications/TeamViewer.app).
    • It checks if the TeamViewer Uninstaller app exists at /Library/Application Support/TeamViewer/TeamViewerUninstaller.app.
    • If no installation is detected, the script identifies whether the portable TeamViewer QuickSupport tool is running, then exits gracefully with an error.
  3. Uninstallation Process

    • Executes the uninstaller binary with the –force flag to remove TeamViewer and associated services.
    • Implements a function waitForTeamViewer that continuously monitors whether TeamViewer processes are still running, with a five-minute timeout. This ensures that background services fully terminate before moving forward.
  4. Verification Phase

    • After the uninstaller finishes, the script double-checks the system by searching for residual application files and uninstaller paths. If any are found, the script raises an error.
  5. Exit

    • If successful, it outputs: TeamViewer has been successfully removed.”

Visually, the process can be represented as:

Detection → Uninstallation → Waiting for process termination → Verification → Success/Failure

Potential Use Cases

Imagine an MSP rolling out a new remote management solution. Before deploying the new software, the IT team needs to ensure that TeamViewer is fully removed from all client devices. Instead of manually uninstalling on each macOS machine, the technician pushes this script via NinjaOne. Within minutes, TeamViewer is gone across the environment, and compliance reports confirm removal.

Comparisons

  • Manual Removal: Dragging the app to Trash leaves background services intact.
  • Third-Party Uninstaller Tools: These may remove the app but introduce licensing and trust concerns.
  • Native TeamViewer Uninstaller: Works well but requires manual initiation.

This shell script combines the reliability of the official uninstaller with automation, verification, and repeatability—making it far superior for enterprise workflows.

Implications

Removing remote access tools like TeamViewer strengthens endpoint security by eliminating unmonitored access points. In compliance-driven industries, this script provides assurance that deprecated software is completely removed, reducing risk exposure.

Recommendations

  • Always run the script with root privileges (sudo).
  • Deploy in test environments before pushing to production.
  • Use alongside reporting tools in NinjaOne to confirm successful uninstallation.
  • Keep the script updated as new TeamViewer versions are released.

Confirm uninstalls, track outcomes, and prove success.

Start your free trial of NinjaOne Reporting.

Final Thoughts

For IT professionals seeking a reliable way to uninstall TeamViewer on macOS, this shell script delivers a complete solution. It automates detection, execution, and verification, ensuring no remnants remain. When combined with NinjaOne’s automation and reporting capabilities, MSPs can confidently remove TeamViewer across large environments while maintaining compliance and security.

This is a professional-grade approach to uninstall TeamViewer on macOS with a shell script, offering repeatability and efficiency that manual methods cannot match.

FAQs

No. QuickSupport is portable and doesn’t install system-wide components, so there’s nothing to uninstall.

Generally no, since the uninstaller path remains consistent. However, validation is recommended after major version changes.

The script waits up to five minutes for processes to stop, ensuring a clean uninstall.

Next Steps

Building an efficient and effective IT team requires a centralized solution that acts as your core service delivery tool. NinjaOne enables IT teams to monitor, manage, secure, and support all their devices, wherever they are, without the need for complex on-premises infrastructure.

Learn more about NinjaOne Remote Script Deployment, check out a live tour, or start your free trial of the NinjaOne platform.

Categories:

You might also like