Tutorial

New updates and improvements to Roundfleet.

Important notice

The code examples and scripts provided in these tutorials are for educational purposes only. Roundfleet is not responsible for any issues, damages, or security vulnerabilities that may arise from the use, modification, or implementation of these examples. Always review and test code in a secure environment before using it in production systems.

Manage Bluetooth Menu on Status Bar in macOS

Managing the visibility of system menus in the status bar is essential for maintaining a consistent user experience across your Mac fleet. This tutorial shows you how to control the Bluetooth menu display on macOS devices using shell scripts.

Why Manage Bluetooth Menu Visibility

Controlling the Bluetooth menu visibility helps with:

  • Consistent user experience: Standardize interface elements across all devices
  • Quick access management: Provide users with convenient Bluetooth controls
  • Support efficiency: Reduce support tickets by ensuring easy access to Bluetooth settings
  • Enterprise compliance: Maintain consistent UI standards across the organization
  • User productivity: Enable quick Bluetooth connection management

Understanding Control Center Configuration

macOS uses the Control Center preference system to manage status bar items. The Bluetooth menu is controlled through the com.apple.controlcenter.plist file with these key values:

  • Value 18: Show Bluetooth menu in status bar
  • Value 0: Hide Bluetooth menu from status bar

Basic Bluetooth Menu Management

Show Bluetooth Menu in Status Bar

#!/bin/bash

# Script to show Bluetooth menu on status bar
CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }')
CurrentUserUID=$(id -u "$CurrentUser")

launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18

echo "Bluetooth menu enabled on status bar for user: $CurrentUser"

Hide Bluetooth Menu from Status Bar

#!/bin/bash

# Script to hide Bluetooth menu from status bar
CurrentUser=$(ls -l /dev/console | awk '/ / { print $3 }')
CurrentUserUID=$(id -u "$CurrentUser")

launchctl asuser $CurrentUserUID sudo -iu "$CurrentUser" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 0

echo "Bluetooth menu hidden from status bar for user: $CurrentUser"

Enhanced Bluetooth Menu Management

Comprehensive Bluetooth Status Script

#!/bin/bash

# Enhanced Bluetooth menu management with validation
DEVICE_NAME=$(scutil --get ComputerName)
CURRENT_USER=$(ls -l /dev/console | awk '/ / { print $3 }')
CURRENT_USER_UID=$(id -u "$CURRENT_USER")
LOG_FILE="/var/log/roundfleet_bluetooth_menu.log"

# Function to log messages
log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}

# Function to get current Bluetooth menu status
get_bluetooth_status() {
    local status=$(launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost read com.apple.controlcenter.plist Bluetooth 2>/dev/null)
    echo "$status"
}

# Function to show Bluetooth menu
show_bluetooth_menu() {
    launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18
    log_message "Bluetooth menu enabled on $DEVICE_NAME for user $CURRENT_USER"
}

# Function to hide Bluetooth menu
hide_bluetooth_menu() {
    launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 0
    log_message "Bluetooth menu hidden on $DEVICE_NAME for user $CURRENT_USER"
}

# Function to validate current state
validate_bluetooth_state() {
    local current_status=$(get_bluetooth_status)
    log_message "Current Bluetooth menu status: $current_status"
    
    if [ "$current_status" = "18" ]; then
        echo "✅ Bluetooth menu is currently visible in status bar"
    elif [ "$current_status" = "0" ]; then
        echo "❌ Bluetooth menu is currently hidden from status bar"
    else
        echo "⚠️  Bluetooth menu status is undefined or not set"
    fi
}

# Main execution
log_message "Starting Bluetooth menu management on $DEVICE_NAME"

# Check current status
validate_bluetooth_state

# Example: Show Bluetooth menu (uncomment to use)
# show_bluetooth_menu

# Example: Hide Bluetooth menu (uncomment to use)
# hide_bluetooth_menu

# Verify change
validate_bluetooth_state
log_message "Bluetooth menu management completed"

Interactive Bluetooth Menu Manager

#!/bin/bash

# Interactive Bluetooth menu manager
CURRENT_USER=$(ls -l /dev/console | awk '/ / { print $3 }')
CURRENT_USER_UID=$(id -u "$CURRENT_USER")

# Function to get current status
get_current_status() {
    local status=$(launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost read com.apple.controlcenter.plist Bluetooth 2>/dev/null)
    case "$status" in
        18) echo "visible" ;;
        0) echo "hidden" ;;
        *) echo "undefined" ;;
    esac
}

# Function to toggle Bluetooth menu
toggle_bluetooth_menu() {
    local current_status=$(get_current_status)
    
    if [ "$current_status" = "visible" ]; then
        launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 0
        echo "Bluetooth menu has been hidden from status bar"
    else
        launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18
        echo "Bluetooth menu has been shown in status bar"
    fi
}

# Display current status
echo "Roundfleet Bluetooth Menu Manager"
echo "==============================="
echo "Device: $(scutil --get ComputerName)"
echo "User: $CURRENT_USER"
echo "Current Bluetooth menu status: $(get_current_status)"
echo ""

# Provide options
echo "Options:"
echo "1. Show Bluetooth menu"
echo "2. Hide Bluetooth menu"
echo "3. Toggle Bluetooth menu"
echo "4. Check current status"
echo ""

read -p "Enter your choice (1-4): " choice

case $choice in
    1)
        launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18
        echo "✅ Bluetooth menu is now visible in status bar"
        ;;
    2)
        launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 0
        echo "❌ Bluetooth menu is now hidden from status bar"
        ;;
    3)
        toggle_bluetooth_menu
        ;;
    4)
        echo "Current status: $(get_current_status)"
        ;;
    *)
        echo "Invalid choice. Please run the script again."
        ;;
esac

Advanced Control Center Management

Comprehensive Control Center Configuration

#!/bin/bash

# Comprehensive Control Center menu management
CURRENT_USER=$(ls -l /dev/console | awk '/ / { print $3 }')
CURRENT_USER_UID=$(id -u "$CURRENT_USER")

# Define Control Center menu items and their values
declare -A control_center_items=(
    ["Bluetooth"]="18"
    ["WiFi"]="18"
    ["AirDrop"]="18"
    ["Focus"]="18"
    ["StageManager"]="18"
    ["Display"]="18"
    ["Sound"]="18"
    ["NowPlaying"]="18"
    ["ScreenMirroring"]="18"
    ["Battery"]="18"
    ["Clock"]="18"
    ["UserSwitcher"]="18"
)

# Function to configure Control Center item
configure_control_center_item() {
    local item="$1"
    local value="$2"
    local action="$3"
    
    launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost write com.apple.controlcenter.plist "$item" -int "$value"
    
    if [ "$value" = "18" ]; then
        echo "✅ $item: Enabled in status bar"
    else
        echo "❌ $item: Disabled in status bar"
    fi
}

# Function to show all Control Center items
show_all_items() {
    echo "Enabling all Control Center items..."
    for item in "${!control_center_items[@]}"; do
        configure_control_center_item "$item" "18"
    done
}

# Function to hide all Control Center items
hide_all_items() {
    echo "Disabling all Control Center items..."
    for item in "${!control_center_items[@]}"; do
        configure_control_center_item "$item" "0"
    done
}

# Function to show current status of all items
show_current_status() {
    echo "Current Control Center Status:"
    echo "=============================="
    
    for item in "${!control_center_items[@]}"; do
        local current_value=$(launchctl asuser $CURRENT_USER_UID sudo -iu "$CURRENT_USER" defaults -currentHost read com.apple.controlcenter.plist "$item" 2>/dev/null)
        
        case "$current_value" in
            18) echo "✅ $item: Visible" ;;
            0) echo "❌ $item: Hidden" ;;
            *) echo "⚠️  $item: Not configured" ;;
        esac
    done
}

# Function to configure essential items only
configure_essential_items() {
    echo "Configuring essential Control Center items..."
    
    # Essential items for most users
    essential_items=("Bluetooth" "WiFi" "Sound" "Battery" "Clock")
    
    # Hide all items first
    hide_all_items
    
    # Show only essential items
    for item in "${essential_items[@]}"; do
        configure_control_center_item "$item" "18"
    done
}

# Main menu
echo "Roundfleet Control Center Manager"
echo "==============================="
echo "Device: $(scutil --get ComputerName)"
echo "User: $CURRENT_USER"
echo ""

show_current_status

echo ""
echo "Management Options:"
echo "1. Show all Control Center items"
echo "2. Hide all Control Center items"
echo "3. Show essential items only"
echo "4. Show only Bluetooth menu"
echo "5. Hide only Bluetooth menu"
echo "6. Check current status"
echo ""

read -p "Enter your choice (1-6): " choice

case $choice in
    1) show_all_items ;;
    2) hide_all_items ;;
    3) configure_essential_items ;;
    4) configure_control_center_item "Bluetooth" "18" ;;
    5) configure_control_center_item "Bluetooth" "0" ;;
    6) show_current_status ;;
    *) echo "Invalid choice. Please run the script again." ;;
esac

echo ""
echo "Configuration completed. Changes may require logout/login to take full effect."

Enterprise Deployment Scripts

Bulk Bluetooth Menu Configuration

#!/bin/bash

# Bulk Bluetooth menu configuration for enterprise deployment
COMPANY_NAME="Roundfleet"
DEPLOYMENT_DATE=$(date +"%Y-%m-%d")
LOG_FILE="/var/log/roundfleet_bluetooth_deployment.log"
REPORT_FILE="/tmp/bluetooth_deployment_report_$(date +%Y%m%d_%H%M%S).txt"

# Configuration settings
BLUETOOTH_ENABLED=true  # Set to false to disable
FORCE_RESTART_CONTROL_CENTER=true

# Function to log messages
log_message() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE"
}

# Function to get device information
get_device_info() {
    local device_name=$(scutil --get ComputerName)
    local device_serial=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk '{print $4}')
    local macos_version=$(sw_vers -productVersion)
    local current_user=$(ls -l /dev/console | awk '/ / { print $3 }')
    
    echo "Device: $device_name"
    echo "Serial: $device_serial"
    echo "macOS: $macos_version"
    echo "User: $current_user"
}

# Function to configure Bluetooth menu
configure_bluetooth_menu() {
    local enable_bluetooth="$1"
    local current_user=$(ls -l /dev/console | awk '/ / { print $3 }')
    local current_user_uid=$(id -u "$current_user")
    
    if [ "$enable_bluetooth" = true ]; then
        launchctl asuser $current_user_uid sudo -iu "$current_user" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18
        log_message "Bluetooth menu enabled for user $current_user"
        echo "✅ Bluetooth menu enabled"
    else
        launchctl asuser $current_user_uid sudo -iu "$current_user" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 0
        log_message "Bluetooth menu disabled for user $current_user"
        echo "❌ Bluetooth menu disabled"
    fi
}

# Function to restart Control Center
restart_control_center() {
    local current_user=$(ls -l /dev/console | awk '/ / { print $3 }')
    local current_user_uid=$(id -u "$current_user")
    
    # Kill Control Center process to force reload
    launchctl asuser $current_user_uid sudo -iu "$current_user" killall ControlCenter 2>/dev/null
    log_message "Control Center restarted for user $current_user"
}

# Function to validate deployment
validate_deployment() {
    local current_user=$(ls -l /dev/console | awk '/ / { print $3 }')
    local current_user_uid=$(id -u "$current_user")
    local bluetooth_status=$(launchctl asuser $current_user_uid sudo -iu "$current_user" defaults -currentHost read com.apple.controlcenter.plist Bluetooth 2>/dev/null)
    
    if [ "$BLUETOOTH_ENABLED" = true ] && [ "$bluetooth_status" = "18" ]; then
        echo "✅ Deployment successful - Bluetooth menu is visible"
        log_message "Deployment validation successful"
        return 0
    elif [ "$BLUETOOTH_ENABLED" = false ] && [ "$bluetooth_status" = "0" ]; then
        echo "✅ Deployment successful - Bluetooth menu is hidden"
        log_message "Deployment validation successful"
        return 0
    else
        echo "❌ Deployment validation failed"
        log_message "Deployment validation failed - Expected: $BLUETOOTH_ENABLED, Got: $bluetooth_status"
        return 1
    fi
}

# Main deployment process
echo "$COMPANY_NAME Bluetooth Menu Deployment" > "$REPORT_FILE"
echo "=========================================" >> "$REPORT_FILE"
echo "Date: $DEPLOYMENT_DATE" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"

get_device_info >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"

log_message "Starting Bluetooth menu deployment"
echo "Starting deployment..." >> "$REPORT_FILE"

# Configure Bluetooth menu
configure_bluetooth_menu $BLUETOOTH_ENABLED

# Restart Control Center if requested
if [ "$FORCE_RESTART_CONTROL_CENTER" = true ]; then
    restart_control_center
    sleep 2
fi

# Validate deployment
if validate_deployment; then
    echo "Status: SUCCESS" >> "$REPORT_FILE"
else
    echo "Status: FAILED" >> "$REPORT_FILE"
fi

log_message "Deployment completed"
echo "Deployment completed. Report saved to: $REPORT_FILE"
cat "$REPORT_FILE"

Remote Bluetooth Menu Management

#!/bin/bash

# Remote Bluetooth menu management with JSON reporting
CENTRAL_SERVER="your-roundfleet-server.com"
DEVICE_ID=$(system_profiler SPHardwareDataType | grep "Serial Number" | awk '{print $4}')
REPORT_FILE="/tmp/bluetooth_menu_report_${DEVICE_ID}.json"

# Function to create JSON report
create_json_report() {
    local device_name=$(scutil --get ComputerName)
    local device_user=$(ls -l /dev/console | awk '/ / { print $3 }')
    local device_user_uid=$(id -u "$device_user")
    local os_version=$(sw_vers -productVersion)
    local timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
    
    # Get current Bluetooth menu status
    local bluetooth_status=$(launchctl asuser $device_user_uid sudo -iu "$device_user" defaults -currentHost read com.apple.controlcenter.plist Bluetooth 2>/dev/null)
    
    cat > "$REPORT_FILE" << EOF
{
  "device_info": {
    "device_id": "$DEVICE_ID",
    "device_name": "$device_name",
    "user": "$device_user",
    "os_version": "$os_version",
    "timestamp": "$timestamp"
  },
  "bluetooth_menu": {
    "status": "$bluetooth_status",
    "visible": $([ "$bluetooth_status" = "18" ] && echo "true" || echo "false"),
    "configured": $([ -n "$bluetooth_status" ] && echo "true" || echo "false")
  },
  "control_center": {
    "items": {
EOF

    # Check other Control Center items
    local items=("WiFi" "AirDrop" "Focus" "Display" "Sound" "NowPlaying" "Battery" "Clock")
    local first_item=true
    
    for item in "${items[@]}"; do
        local item_status=$(launchctl asuser $device_user_uid sudo -iu "$device_user" defaults -currentHost read com.apple.controlcenter.plist "$item" 2>/dev/null)
        
        if [ "$first_item" = false ]; then
            echo "," >> "$REPORT_FILE"
        fi
        
        echo "      \"$item\": {" >> "$REPORT_FILE"
        echo "        \"status\": \"$item_status\"," >> "$REPORT_FILE"
        echo "        \"visible\": $([ "$item_status" = "18" ] && echo "true" || echo "false")" >> "$REPORT_FILE"
        echo "      }" >> "$REPORT_FILE"
        
        first_item=false
    done
    
    echo "" >> "$REPORT_FILE"
    echo "    }" >> "$REPORT_FILE"
    echo "  }" >> "$REPORT_FILE"
    echo "}" >> "$REPORT_FILE"
}

# Function to apply configuration from server
apply_server_config() {
    local config_url="https://$CENTRAL_SERVER/api/device-config/$DEVICE_ID"
    
    # Download configuration (example)
    # curl -s "$config_url" -o "/tmp/device_config.json"
    
    # For demonstration, we'll use a local example
    echo "Applying server configuration..."
    
    # Example: Enable Bluetooth menu
    local current_user=$(ls -l /dev/console | awk '/ / { print $3 }')
    local current_user_uid=$(id -u "$current_user")
    
    launchctl asuser $current_user_uid sudo -iu "$current_user" defaults -currentHost write com.apple.controlcenter.plist Bluetooth -int 18
    
    echo "Server configuration applied successfully"
}

# Main execution
echo "Roundfleet Remote Bluetooth Menu Management"
echo "========================================"
echo "Device ID: $DEVICE_ID"

# Create initial report
create_json_report

# Display current status
echo "Current Bluetooth menu status: $(grep -o '"visible": [^,]*' "$REPORT_FILE" | head -1 | cut -d' ' -f2)"

# Apply server configuration if needed
# apply_server_config

# Create final report
create_json_report

echo "Report generated: $REPORT_FILE"
echo "Device reporting completed"

# Optional: Send to central server
# curl -X POST -H "Content-Type: application/json" -d @"$REPORT_FILE" "https://$CENTRAL_SERVER/api/device-reports"

Best Practices for Status Bar Management

1. User Experience Considerations

  • Maintain consistent status bar layouts across all devices
  • Provide essential tools while avoiding clutter
  • Consider user workflow requirements

2. Deployment Strategy

  • Test configuration changes on a small group first
  • Document standard configurations for different user types
  • Provide rollback procedures

3. Change Management

  • Notify users of interface changes in advance
  • Provide training materials for new configurations
  • Monitor support requests after changes

4. Monitoring and Maintenance

  • Regular audits of status bar configurations
  • Automated compliance checking
  • User feedback collection

Troubleshooting Common Issues

Issue: Changes Not Taking Effect

# Force Control Center restart
killall ControlCenter
sleep 2

# Check if preferences are properly written
defaults -currentHost read com.apple.controlcenter.plist Bluetooth

Issue: Permission Denied

# Verify user context
current_user=$(ls -l /dev/console | awk '/ / { print $3 }')
echo "Current user: $current_user"

# Check user permissions
id "$current_user"

Issue: macOS Version Compatibility

# Check macOS version
macos_version=$(sw_vers -productVersion)
echo "macOS version: $macos_version"

# For macOS 12.0 and below, use different preference location
if [[ "$macos_version" < "12.0" ]]; then
    echo "Using legacy preferences location"
    # Use different defaults domain for older versions
fi

Issue: Preferences Not Persisting

# Force preferences synchronization
defaults -currentHost synchronize

# Check if preferences file exists
ls -la ~/Library/Preferences/ByHost/com.apple.controlcenter.*

Conclusion

Managing Bluetooth menu visibility in the status bar is a simple but effective way to standardize the user experience across your Mac fleet. These scripts provide:

  • Consistent interface: Standardized status bar layouts
  • Remote management: Centralized control over UI elements
  • User productivity: Quick access to essential controls
  • Enterprise compliance: Maintaining organizational standards

Regular implementation of these status bar management practices will help ensure a consistent and productive user experience across your entire Mac fleet.

For more advanced Control Center management, consider integrating these scripts with your existing device management and configuration tools.

Related Tutorials

Bluetooth Management on macOS

Comprehensive guide to managing Bluetooth settings, monitoring status, and controlling power states on macOS devices using defaults commands and bluetoothd daemon management for enterprise environments.

Jul 7, 2025

Wi-Fi Network Management on macOS

Manage Wi-Fi networks, configure proxy settings, DNS servers, and implement enterprise network policies on macOS devices using advanced networksetup commands and centralized fleet management.

Jul 7, 2025

Wi-Fi Control on macOS

Comprehensive guide to controlling Wi-Fi settings on macOS devices using networksetup commands for enterprise wireless management, security policies, and power optimization across fleet deployments.

Jul 7, 2025

Proxy Management on macOS

Comprehensive guide to configuring and managing web, secure web, streaming, Gopher, and SOCKS firewall proxies on macOS devices using networksetup commands for enterprise environments.

Jul 7, 2025

Network Monitoring on macOS

Monitor and analyze network-connected applications and processes on macOS devices using advanced network monitoring, bandwidth analysis, and enterprise security controls for organizational network management.

Jul 7, 2025

Retrieve Network Information on macOS

Learn how to gather comprehensive network information including MAC addresses, IP addresses, port status, and ARP tables on macOS devices using command-line scripts.

Jul 7, 2025

System Preferences Management on macOS

Learn how to hide, disable, and manage System Preferences panes on macOS devices using command-line scripts for enterprise configuration and user restriction control.

Jul 7, 2025

System Information Management on macOS

Collect, analyze, and manage system information across macOS devices using advanced system profiling, automated data collection, and enterprise analytics for comprehensive device inventory and monitoring.

Jul 7, 2025