Tutorial

Neue Updates und Verbesserungen zu Macfleet.

Wichtiger Hinweis

Die in diesen Tutorials bereitgestellten Codebeispiele und Skripte dienen nur zu Bildungszwecken. Macfleet ist nicht verantwortlich für Probleme, Schäden oder Sicherheitslücken, die durch die Verwendung, Änderung oder Implementierung dieser Beispiele entstehen können. Überprüfen und testen Sie Code immer in einer sicheren Umgebung, bevor Sie ihn in Produktionssystemen verwenden.

Display Brightness Management and Energy Optimization on macOS

Manage display brightness and energy consumption across your MacFleet devices with comprehensive brightness control, adaptive lighting policies, and enterprise energy optimization tools. This tutorial covers brightness adjustment, automated scheduling, and fleet-wide display management.

Understanding Display Brightness Management

Display brightness control on macOS affects both user experience and energy consumption. Enterprise management includes:

  • Brightness Control - Direct adjustment of display luminosity levels
  • Adaptive Lighting - Automatic adjustment based on environment and time
  • Energy Optimization - Battery conservation through intelligent display management
  • User Experience - Consistent display settings across enterprise devices

Enterprise Benefits

Proper display brightness management provides enterprise advantages:

  • Energy Conservation - Reduced power consumption and extended battery life
  • User Comfort - Optimal viewing conditions for different work environments
  • Security Enhancement - Dimmed displays in public spaces for privacy
  • Health Benefits - Reduced eye strain through proper lighting
  • Standardization - Consistent display experience across device fleet

Basic Brightness Control

Prerequisites and Setup

#!/bin/bash

# Install Homebrew and brightness control tool
install_brightness_tools() {
    echo "=== Installing Brightness Control Tools ==="
    
    # Check if Homebrew is installed
    if ! command -v brew >/dev/null 2>&1; then
        echo "Installing Homebrew..."
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
        
        # Add Homebrew to PATH for current session
        eval "$(/opt/homebrew/bin/brew shellenv)" 2>/dev/null || eval "$(/usr/local/bin/brew shellenv)" 2>/dev/null
    else
        echo "✓ Homebrew already installed"
    fi
    
    # Install brightness control tool
    if ! command -v brightness >/dev/null 2>&1; then
        echo "Installing brightness control tool..."
        brew install brightness
    else
        echo "✓ Brightness tool already installed"
    fi
    
    echo "✓ Brightness control tools installation complete"
}

# Usage
install_brightness_tools

Basic Brightness Commands

#!/bin/bash

# Set brightness to specific levels
set_brightness() {
    local level="$1"
    
    if [[ -z "$level" ]]; then
        echo "Usage: set_brightness <level>"
        echo "Level should be between 0.0 (dark) and 1.0 (brightest)"
        return 1
    fi
    
    # Validate brightness level
    if ! [[ "$level" =~ ^[0-9]*\.?[0-9]+$ ]] || (( $(echo "$level > 1.0" | bc -l) )) || (( $(echo "$level < 0.0" | bc -l) )); then
        echo "Error: Brightness level must be between 0.0 and 1.0"
        return 1
    fi
    
    echo "Setting brightness to ${level} ($(echo "$level * 100" | bc)%)"
    
    # Try different brightness command locations
    if command -v brightness >/dev/null 2>&1; then
        brightness "$level"
    elif [[ -x "/usr/local/bin/brightness" ]]; then
        /usr/local/bin/brightness "$level"
    elif [[ -x "/opt/homebrew/bin/brightness" ]]; then
        /opt/homebrew/bin/brightness "$level"
    elif [[ -x "/usr/local/Cellar/brightness/1.2/bin/brightness" ]]; then
        /usr/local/Cellar/brightness/1.2/bin/brightness "$level"
    else
        echo "Error: Brightness control tool not found"
        return 1
    fi
    
    echo "✓ Brightness set to ${level}"
}

# Predefined brightness levels
set_brightness_full() {
    echo "Setting brightness to 100%"
    set_brightness "1.0"
}

set_brightness_high() {
    echo "Setting brightness to 75%"
    set_brightness "0.75"
}

set_brightness_medium() {
    echo "Setting brightness to 50%"
    set_brightness "0.5"
}

set_brightness_low() {
    echo "Setting brightness to 25%"
    set_brightness "0.25"
}

set_brightness_dim() {
    echo "Setting brightness to 10%"
    set_brightness "0.1"
}

# Usage examples
set_brightness_medium

Get Current Brightness Level

#!/bin/bash

# Get current brightness level
get_current_brightness() {
    echo "=== Current Display Brightness ==="
    
    # Try to get brightness using different methods
    local current_brightness=""
    
    # Method 1: Using brightness command
    if command -v brightness >/dev/null 2>&1; then
        current_brightness=$(brightness -l 2>/dev/null | grep -o '[0-9]*\.[0-9]*' | head -1)
    fi
    
    # Method 2: Using system_profiler (fallback)
    if [[ -z "$current_brightness" ]]; then
        current_brightness=$(system_profiler SPDisplaysDataType | grep -i "brightness" | awk '{print $2}' | head -1)
    fi
    
    # Method 3: Using ioreg (alternative fallback)
    if [[ -z "$current_brightness" ]]; then
        local brightness_raw=$(ioreg -c AppleBacklightDisplay | grep brightness | head -1)
        if [[ -n "$brightness_raw" ]]; then
            current_brightness=$(echo "$brightness_raw" | grep -o '[0-9]*\.[0-9]*')
        fi
    fi
    
    if [[ -n "$current_brightness" ]]; then
        local percentage=$(echo "$current_brightness * 100" | bc)
        echo "Current Brightness: $current_brightness (${percentage}%)"
        return 0
    else
        echo "Unable to determine current brightness level"
        return 1
    fi
}

# Usage
get_current_brightness

Advanced Brightness Management

Adaptive Brightness Control

#!/bin/bash

# Adaptive brightness based on time of day and conditions
adaptive_brightness_control() {
    local mode="${1:-auto}"
    local location_lat="${2:-}"
    local location_lon="${3:-}"
    
    echo "=== Adaptive Brightness Control ==="
    echo "Mode: $mode"
    echo "Date: $(date)"
    echo ""
    
    case "$mode" in
        "auto")
            automatic_brightness_adjustment
            ;;
        "schedule")
            scheduled_brightness_adjustment
            ;;
        "ambient")
            ambient_light_brightness "$location_lat" "$location_lon"
            ;;
        "work_hours")
            work_hours_brightness
            ;;
        "battery_saver")
            battery_aware_brightness
            ;;
        *)
            echo "Unknown mode: $mode"
            echo "Available modes: auto, schedule, ambient, work_hours, battery_saver"
            return 1
            ;;
    esac
}

# Automatic brightness based on time of day
automatic_brightness_adjustment() {
    local current_hour=$(date +%H)
    local current_minute=$(date +%M)
    local time_decimal=$(echo "$current_hour + $current_minute / 60" | bc -l)
    
    echo "--- Automatic Brightness Adjustment ---"
    echo "Current time: $current_hour:$(printf "%02d" $current_minute)"
    
    local brightness_level
    
    if (( $(echo "$time_decimal >= 6 && $time_decimal < 9" | bc -l) )); then
        # Morning: Gradual increase
        brightness_level="0.4"
        echo "Time period: Morning (6:00-9:00) - Setting moderate brightness"
    elif (( $(echo "$time_decimal >= 9 && $time_decimal < 17" | bc -l) )); then
        # Work hours: Full brightness
        brightness_level="0.8"
        echo "Time period: Work hours (9:00-17:00) - Setting high brightness"
    elif (( $(echo "$time_decimal >= 17 && $time_decimal < 20" | bc -l) )); then
        # Evening: Medium brightness
        brightness_level="0.6"
        echo "Time period: Evening (17:00-20:00) - Setting medium brightness"
    elif (( $(echo "$time_decimal >= 20 && $time_decimal < 22" | bc -l) )); then
        # Night: Low brightness
        brightness_level="0.3"
        echo "Time period: Night (20:00-22:00) - Setting low brightness"
    else
        # Late night/early morning: Very low
        brightness_level="0.1"
        echo "Time period: Late night/Early morning - Setting very low brightness"
    fi
    
    set_brightness "$brightness_level"
}

# Scheduled brightness changes
scheduled_brightness_adjustment() {
    echo "--- Scheduled Brightness Adjustment ---"
    
    # Define schedule (hour:brightness_level)
    local schedule=(
        "06:00:0.3"  # Dawn
        "08:00:0.6"  # Morning
        "09:00:0.8"  # Work start
        "12:00:0.9"  # Midday
        "17:00:0.7"  # Work end
        "19:00:0.5"  # Evening
        "21:00:0.3"  # Night
        "23:00:0.1"  # Late night
    )
    
    local current_time=$(date +%H:%M)
    echo "Current time: $current_time"
    
    # Find the appropriate brightness level for current time
    local target_brightness="0.5"  # Default
    
    for schedule_entry in "${schedule[@]}"; do
        IFS=':' read -r schedule_time schedule_brightness <<< "$schedule_entry"
        
        if [[ "$current_time" > "$schedule_time" ]] || [[ "$current_time" == "$schedule_time" ]]; then
            target_brightness="$schedule_brightness"
        fi
    done
    
    echo "Scheduled brightness level: $target_brightness"
    set_brightness "$target_brightness"
}

# Battery-aware brightness management
battery_aware_brightness() {
    echo "--- Battery-Aware Brightness Management ---"
    
    # Get battery information
    local battery_info=$(pmset -g batt)
    local battery_percentage=$(echo "$battery_info" | grep -o '[0-9]*%' | head -1 | tr -d '%')
    local power_source=$(echo "$battery_info" | grep -o "AC Power\|Battery Power" | head -1)
    
    echo "Battery level: ${battery_percentage}%"
    echo "Power source: $power_source"
    
    local brightness_level
    
    if [[ "$power_source" == "AC Power" ]]; then
        # On AC power - normal brightness
        brightness_level="0.8"
        echo "On AC power - Setting normal brightness"
    else
        # On battery - adjust based on battery level
        if [[ $battery_percentage -gt 50 ]]; then
            brightness_level="0.6"
            echo "Battery > 50% - Setting medium brightness"
        elif [[ $battery_percentage -gt 20 ]]; then
            brightness_level="0.4"
            echo "Battery 20-50% - Setting low brightness"
        else
            brightness_level="0.2"
            echo "Battery < 20% - Setting very low brightness"
        fi
    fi
    
    set_brightness "$brightness_level"
}

# Usage
adaptive_brightness_control "auto"

Display Environment Analysis

#!/bin/bash

# Analyze display environment and recommend brightness
analyze_display_environment() {
    echo "=== Display Environment Analysis ==="
    echo "Analysis Date: $(date)"
    echo ""
    
    # System information
    echo "--- System Information ---"
    local hostname=$(hostname)
    local os_version=$(sw_vers -productVersion)
    local hardware_model=$(system_profiler SPHardwareDataType | grep "Model Identifier" | awk '{print $3}')
    
    echo "Hostname: $hostname"
    echo "macOS Version: $os_version"
    echo "Hardware Model: $hardware_model"
    
    # Display information
    echo ""
    echo "--- Display Information ---"
    local display_info=$(system_profiler SPDisplaysDataType)
    local display_count=$(echo "$display_info" | grep "Display Type" | wc -l | tr -d ' ')
    
    echo "Number of displays: $display_count"
    
    # Extract display details
    if [[ $display_count -gt 0 ]]; then
        echo "$display_info" | grep -E "(Display Type|Resolution|Main Display)" | while read -r line; do
            echo "  $line"
        done
    fi
    
    # Power and battery analysis
    echo ""
    echo "--- Power Analysis ---"
    local power_info=$(pmset -g batt)
    echo "$power_info"
    
    # Check if device supports ambient light sensor
    echo ""
    echo "--- Ambient Light Sensor ---"
    if ioreg -c IOHIDSystem | grep -q "AmbientLightSensor"; then
        echo "✓ Ambient light sensor detected"
        
        # Try to get ambient light reading
        local ambient_light=$(ioreg -c IOHIDSystem | grep "AmbientLightSensor" -A 10 | grep "AmbientLightValue" | awk '{print $3}')
        if [[ -n "$ambient_light" ]]; then
            echo "Ambient light level: $ambient_light lux"
        fi
    else
        echo "⚠️ No ambient light sensor detected"
    fi
    
    # Recommendations
    echo ""
    echo "--- Brightness Recommendations ---"
    recommend_brightness_settings
}

# Recommend brightness settings based on environment
recommend_brightness_settings() {
    local current_hour=$(date +%H)
    local battery_info=$(pmset -g batt)
    local battery_percentage=$(echo "$battery_info" | grep -o '[0-9]*%' | head -1 | tr -d '%')
    local power_source=$(echo "$battery_info" | grep -o "AC Power\|Battery Power" | head -1)
    
    echo "Based on current conditions:"
    echo "- Time: $current_hour:00"
    echo "- Power: $power_source"
    echo "- Battery: ${battery_percentage}%"
    echo ""
    
    # Time-based recommendations
    if [[ $current_hour -ge 6 && $current_hour -lt 9 ]]; then
        echo "Morning recommendation: 40-60% brightness for gradual eye adjustment"
    elif [[ $current_hour -ge 9 && $current_hour -lt 17 ]]; then
        echo "Work hours recommendation: 70-90% brightness for optimal productivity"
    elif [[ $current_hour -ge 17 && $current_hour -lt 20 ]]; then
        echo "Evening recommendation: 50-70% brightness for comfortable viewing"
    else
        echo "Night recommendation: 10-30% brightness to reduce eye strain"
    fi
    
    # Power-based recommendations
    if [[ "$power_source" == "Battery Power" && $battery_percentage -lt 30 ]]; then
        echo "Low battery recommendation: Reduce brightness to 20-40% to conserve power"
    fi
}

# Usage
analyze_display_environment

Enterprise Display Management System

#!/bin/bash

# MacFleet Display Brightness Management Tool
# Comprehensive display control, energy optimization, and fleet management

# Configuration
SCRIPT_VERSION="1.0.0"
LOG_FILE="/var/log/macfleet_display_management.log"
REPORT_DIR="/etc/macfleet/reports/display"
CONFIG_DIR="/etc/macfleet/display"
POLICY_DIR="/etc/macfleet/policies/display"
SCHEDULE_DIR="/etc/macfleet/schedules/display"

# Create directories if they don't exist
mkdir -p "$REPORT_DIR" "$CONFIG_DIR" "$POLICY_DIR" "$SCHEDULE_DIR"

# Display management policy templates
declare -A DISPLAY_POLICIES=(
    ["enterprise_standard"]="adaptive_brightness,battery_optimization,work_hours_profile,user_override_limited"
    ["energy_saver"]="aggressive_dimming,battery_priority,low_brightness_default,power_aware_scheduling"
    ["presentation_mode"]="high_brightness,stable_settings,no_auto_dimming,optimal_visibility"
    ["kiosk_display"]="fixed_brightness,no_user_control,scheduled_adjustments,energy_optimized"
    ["healthcare"]="eye_strain_reduction,shift_appropriate,patient_privacy,energy_conscious"
    ["financial"]="security_dimming,privacy_protection,energy_compliance,professional_display"
    ["education"]="classroom_optimized,energy_teaching,adaptive_learning,student_friendly"
    ["retail"]="customer_facing,bright_displays,brand_consistency,operational_hours"
    ["manufacturing"]="industrial_visibility,safety_priority,harsh_environment,energy_efficient"
    ["government"]="security_compliant,energy_mandates,accessibility_aware,audit_ready"
)

# Brightness profiles for different use cases
declare -A BRIGHTNESS_PROFILES=(
    ["work_day"]="morning:0.4,work_start:0.8,lunch:0.9,afternoon:0.8,work_end:0.6"
    ["energy_saver"]="morning:0.3,work_start:0.6,lunch:0.7,afternoon:0.6,work_end:0.4"
    ["presentation"]="all_day:0.9,constant_high:1.0"
    ["night_shift"]="evening:0.4,night:0.2,late_night:0.1,dawn:0.3"
    ["retail_hours"]="open:0.9,peak:1.0,closing:0.7,after_hours:0.2"
    ["healthcare_24"]="day_shift:0.7,evening_shift:0.5,night_shift:0.3,emergency:0.8"
)

# Energy optimization thresholds
declare -A ENERGY_THRESHOLDS=(
    ["battery_critical"]="20:0.2"      # Below 20% battery: 20% brightness
    ["battery_low"]="30:0.4"           # Below 30% battery: 40% brightness
    ["battery_medium"]="50:0.6"        # Below 50% battery: 60% brightness
    ["battery_high"]="80:0.8"          # Above 80% battery: 80% brightness
    ["ac_power"]="100:0.9"             # On AC power: 90% brightness
)

# Logging function
log_action() {
    local message="$1"
    local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
    echo "[$timestamp] $message" | tee -a "$LOG_FILE"
}

# Enhanced brightness control with validation
set_brightness_enhanced() {
    local brightness_level="$1"
    local reason="${2:-Manual adjustment}"
    local user="${3:-$(whoami)}"
    
    log_action "Setting brightness to $brightness_level for user $user - Reason: $reason"
    
    # Validate brightness level
    if ! [[ "$brightness_level" =~ ^[0-9]*\.?[0-9]+$ ]] || 
       (( $(echo "$brightness_level > 1.0" | bc -l) )) || 
       (( $(echo "$brightness_level < 0.0" | bc -l) )); then
        log_action "ERROR: Invalid brightness level: $brightness_level"
        return 1
    fi
    
    # Store previous brightness for rollback capability
    local previous_brightness=$(get_current_brightness_value)
    
    # Apply brightness change
    local brightness_cmd=""
    if command -v brightness >/dev/null 2>&1; then
        brightness_cmd="brightness"
    elif [[ -x "/opt/homebrew/bin/brightness" ]]; then
        brightness_cmd="/opt/homebrew/bin/brightness"
    elif [[ -x "/usr/local/bin/brightness" ]]; then
        brightness_cmd="/usr/local/bin/brightness"
    elif [[ -x "/usr/local/Cellar/brightness/1.2/bin/brightness" ]]; then
        brightness_cmd="/usr/local/Cellar/brightness/1.2/bin/brightness"
    else
        log_action "ERROR: Brightness control command not found"
        return 1
    fi
    
    if $brightness_cmd "$brightness_level" 2>/dev/null; then
        local percentage=$(echo "$brightness_level * 100" | bc)
        log_action "SUCCESS: Brightness set to $brightness_level (${percentage}%)"
        
        # Record change in history
        echo "$(date '+%Y-%m-%d %H:%M:%S'),$user,$previous_brightness,$brightness_level,$reason" >> "$CONFIG_DIR/brightness_history.csv"
        
        return 0
    else
        log_action "ERROR: Failed to set brightness to $brightness_level"
        return 1
    fi
}

# Get current brightness as numeric value
get_current_brightness_value() {
    local current_brightness=""
    
    if command -v brightness >/dev/null 2>&1; then
        current_brightness=$(brightness -l 2>/dev/null | grep -o '[0-9]*\.[0-9]*' | head -1)
    fi
    
    if [[ -n "$current_brightness" ]]; then
        echo "$current_brightness"
    else
        echo "0.5"  # Default fallback
    fi
}

# Apply brightness profile
apply_brightness_profile() {
    local profile_name="$1"
    local override_time="${2:-}"
    
    log_action "Applying brightness profile: $profile_name"
    
    if [[ -z "${BRIGHTNESS_PROFILES[$profile_name]}" ]]; then
        log_action "ERROR: Unknown brightness profile: $profile_name"
        echo "Available profiles: ${!BRIGHTNESS_PROFILES[*]}"
        return 1
    fi
    
    local profile_settings="${BRIGHTNESS_PROFILES[$profile_name]}"
    local current_time="${override_time:-$(date +%H:%M)}"
    local current_hour=$(echo "$current_time" | cut -d: -f1)
    
    echo "=== Applying Brightness Profile: $profile_name ==="
    echo "Current time: $current_time"
    echo "Profile settings: $profile_settings"
    
    # Parse profile settings and find appropriate brightness
    local target_brightness="0.5"  # Default
    local matched_period="default"
    
    IFS=',' read -ra SETTINGS <<< "$profile_settings"
    for setting in "${SETTINGS[@]}"; do
        IFS=':' read -ra TIME_BRIGHTNESS <<< "$setting"
        local time_period="${TIME_BRIGHTNESS[0]}"
        local brightness_value="${TIME_BRIGHTNESS[1]}"
        
        case "$time_period" in
            "morning")
                if [[ $current_hour -ge 6 && $current_hour -lt 9 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="morning"
                fi
                ;;
            "work_start"|"work")
                if [[ $current_hour -ge 9 && $current_hour -lt 12 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="work_start"
                fi
                ;;
            "lunch"|"midday")
                if [[ $current_hour -ge 12 && $current_hour -lt 14 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="lunch"
                fi
                ;;
            "afternoon")
                if [[ $current_hour -ge 14 && $current_hour -lt 17 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="afternoon"
                fi
                ;;
            "work_end"|"evening")
                if [[ $current_hour -ge 17 && $current_hour -lt 20 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="evening"
                fi
                ;;
            "night")
                if [[ $current_hour -ge 20 && $current_hour -lt 23 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="night"
                fi
                ;;
            "late_night")
                if [[ $current_hour -ge 23 || $current_hour -lt 6 ]]; then
                    target_brightness="$brightness_value"
                    matched_period="late_night"
                fi
                ;;
            "all_day"|"constant_high")
                target_brightness="$brightness_value"
                matched_period="all_day"
                ;;
        esac
    done
    
    echo "Matched time period: $matched_period"
    echo "Target brightness: $target_brightness"
    
    # Apply the brightness
    set_brightness_enhanced "$target_brightness" "Profile: $profile_name ($matched_period)"
}

# Energy-aware brightness management
energy_aware_brightness() {
    local policy="${1:-balanced}"
    
    log_action "Starting energy-aware brightness management with policy: $policy"
    
    echo "=== Energy-Aware Brightness Management ==="
    echo "Policy: $policy"
    echo ""
    
    # Get power status
    local battery_info=$(pmset -g batt)
    local battery_percentage=$(echo "$battery_info" | grep -o '[0-9]*%' | head -1 | tr -d '%')
    local power_source=$(echo "$battery_info" | grep -o "AC Power\|Battery Power" | head -1)
    local charging_status=$(echo "$battery_info" | grep -o "charging\|charged\|discharging" | head -1)
    
    echo "--- Power Status ---"
    echo "Power Source: $power_source"
    echo "Battery Level: ${battery_percentage}%"
    echo "Charging Status: $charging_status"
    
    # Determine brightness based on energy policy
    local target_brightness=""
    local energy_reason=""
    
    case "$policy" in
        "aggressive")
            if [[ "$power_source" == "AC Power" ]]; then
                target_brightness="0.8"
                energy_reason="AC power - normal brightness"
            else
                if [[ $battery_percentage -lt 20 ]]; then
                    target_brightness="0.15"
                    energy_reason="Critical battery - minimum brightness"
                elif [[ $battery_percentage -lt 40 ]]; then
                    target_brightness="0.25"
                    energy_reason="Low battery - very low brightness"
                else
                    target_brightness="0.4"
                    energy_reason="Battery power - low brightness"
                fi
            fi
            ;;
        "balanced")
            if [[ "$power_source" == "AC Power" ]]; then
                target_brightness="0.8"
                energy_reason="AC power - normal brightness"
            else
                if [[ $battery_percentage -lt 20 ]]; then
                    target_brightness="0.2"
                    energy_reason="Low battery - reduced brightness"
                elif [[ $battery_percentage -lt 50 ]]; then
                    target_brightness="0.4"
                    energy_reason="Medium battery - moderate brightness"
                else
                    target_brightness="0.6"
                    energy_reason="Good battery - normal brightness"
                fi
            fi
            ;;
        "performance")
            if [[ "$power_source" == "AC Power" ]]; then
                target_brightness="0.9"
                energy_reason="AC power - high brightness"
            else
                if [[ $battery_percentage -lt 15 ]]; then
                    target_brightness="0.3"
                    energy_reason="Critical battery - power saving"
                else
                    target_brightness="0.7"
                    energy_reason="Battery power - maintain visibility"
                fi
            fi
            ;;
    esac
    
    echo ""
    echo "--- Energy Decision ---"
    echo "Policy: $policy"
    echo "Decision: $energy_reason"
    echo "Target Brightness: $target_brightness"
    
    # Apply brightness change
    set_brightness_enhanced "$target_brightness" "$energy_reason"
    
    # Log energy savings estimate
    local current_brightness=$(get_current_brightness_value)
    local energy_savings=$(echo "($current_brightness - $target_brightness) * 20" | bc)  # Rough estimate
    
    if (( $(echo "$energy_savings > 0" | bc -l) )); then
        echo "Estimated energy savings: ${energy_savings}% display power reduction"
        log_action "Energy savings estimated: ${energy_savings}% display power reduction"
    fi
}

# Fleet brightness management
manage_fleet_brightness() {
    local operation="$1"
    local target_brightness="$2"
    local fleet_scope="${3:-local}"
    
    log_action "Fleet brightness management: $operation (scope: $fleet_scope)"
    
    echo "=== Fleet Brightness Management ==="
    echo "Operation: $operation"
    echo "Target Brightness: $target_brightness"
    echo "Fleet Scope: $fleet_scope"
    echo ""
    
    case "$operation" in
        "set_all")
            echo "Setting brightness to $target_brightness across fleet..."
            set_brightness_enhanced "$target_brightness" "Fleet-wide adjustment"
            ;;
        "energy_optimize")
            echo "Optimizing brightness for energy efficiency..."
            energy_aware_brightness "balanced"
            ;;
        "sync_profiles")
            echo "Synchronizing brightness profiles across fleet..."
            apply_brightness_profile "work_day"
            ;;
        "emergency_dim")
            echo "Applying emergency dimming for power conservation..."
            set_brightness_enhanced "0.1" "Emergency power conservation"
            ;;
        "restore_normal")
            echo "Restoring normal brightness levels..."
            apply_brightness_profile "work_day"
            ;;
        *)
            log_action "ERROR: Unknown fleet operation: $operation"
            return 1
            ;;
    esac
    
    # Generate fleet status report
    generate_brightness_status_report
}

# Generate brightness status report
generate_brightness_status_report() {
    local report_file="$REPORT_DIR/brightness_status_$(date +%Y%m%d_%H%M%S).json"
    
    local current_brightness=$(get_current_brightness_value)
    local battery_info=$(pmset -g batt)
    local battery_percentage=$(echo "$battery_info" | grep -o '[0-9]*%' | head -1 | tr -d '%')
    local power_source=$(echo "$battery_info" | grep -o "AC Power\|Battery Power" | head -1)
    
    cat > "$report_file" << EOF
{
    "brightness_status_report": {
        "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
        "hostname": "$(hostname)",
        "script_version": "$SCRIPT_VERSION",
        "display_status": {
            "current_brightness": $current_brightness,
            "brightness_percentage": $(echo "$current_brightness * 100" | bc),
            "power_source": "$power_source",
            "battery_level": $battery_percentage
        },
        "system_info": {
            "os_version": "$(sw_vers -productVersion)",
            "hardware_model": "$(system_profiler SPHardwareDataType | grep 'Model Identifier' | awk '{print $3}')",
            "display_count": $(system_profiler SPDisplaysDataType | grep "Display Type" | wc -l | tr -d ' ')
        }
    }
}
EOF
    
    echo "Brightness status report generated: $report_file"
    log_action "Status report generated: $report_file"
}

# Main execution function
main() {
    local action="${1:-help}"
    local param1="${2:-}"
    local param2="${3:-}"
    local param3="${4:-}"
    local param4="${5:-}"
    
    log_action "=== MacFleet Display Brightness Management Started ==="
    log_action "Action: $action"
    
    case "$action" in
        "set")
            if [[ -z "$param1" ]]; then
                echo "Usage: $0 set <brightness_level> [reason]"
                echo "Brightness level: 0.0-1.0 (0-100%)"
                exit 1
            fi
            set_brightness_enhanced "$param1" "${param2:-Manual setting}"
            ;;
        "get")
            echo "Current brightness: $(get_current_brightness_value)"
            ;;
        "profile")
            if [[ -z "$param1" ]]; then
                echo "Available profiles: ${!BRIGHTNESS_PROFILES[*]}"
                exit 1
            fi
            apply_brightness_profile "$param1" "$param2"
            ;;
        "energy")
            energy_aware_brightness "${param1:-balanced}"
            ;;
        "analyze")
            analyze_display_environment
            ;;
        "fleet")
            if [[ -z "$param1" ]]; then
                echo "Usage: $0 fleet <operation> [brightness] [scope]"
                echo "Operations: set_all, energy_optimize, sync_profiles, emergency_dim, restore_normal"
                exit 1
            fi
            manage_fleet_brightness "$param1" "$param2" "$param3"
            ;;
        "adaptive")
            adaptive_brightness_control "${param1:-auto}"
            ;;
        "install")
            install_brightness_tools
            ;;
        "help")
            echo "Usage: $0 [action] [options...]"
            echo "Actions:"
            echo "  set <level> [reason] - Set brightness level (0.0-1.0)"
            echo "  get - Get current brightness level"
            echo "  profile <name> [time] - Apply brightness profile"
            echo "  energy [policy] - Energy-aware brightness management"
            echo "  analyze - Analyze display environment"
            echo "  fleet <operation> [params] - Fleet brightness management"
            echo "  adaptive [mode] - Adaptive brightness control"
            echo "  install - Install brightness control tools"
            echo "  help - Show this help"
            echo ""
            echo "Profiles: ${!BRIGHTNESS_PROFILES[*]}"
            echo "Policies: ${!DISPLAY_POLICIES[*]}"
            ;;
        *)
            log_action "ERROR: Unknown action: $action"
            echo "Use '$0 help' for usage information"
            exit 1
            ;;
    esac
    
    log_action "=== Display brightness management completed ==="
}

# Execute main function
main "$@"

Important Notes

  • Homebrew Required - The brightness control tool requires Homebrew installation
  • Intel Mac Support - Some brightness commands work only on Intel-based Macs
  • Battery Awareness - Brightness should be adjusted based on power source and battery level
  • User Experience - Sudden brightness changes can be jarring; implement gradual transitions
  • Enterprise Policies - Different work environments require different brightness strategies
  • Energy Conservation - Lower brightness significantly extends battery life
  • Health Considerations - Proper brightness reduces eye strain and fatigue

Tutorial

Neue Updates und Verbesserungen zu Macfleet.

Konfiguration eines GitHub Actions Runners auf einem Mac Mini (Apple Silicon)

GitHub Actions Runner

GitHub Actions ist eine leistungsstarke CI/CD-Plattform, die es Ihnen ermöglicht, Ihre Software-Entwicklungsworkflows zu automatisieren. Während GitHub gehostete Runner anbietet, bieten selbst-gehostete Runner erhöhte Kontrolle und Anpassung für Ihr CI/CD-Setup. Dieses Tutorial führt Sie durch die Einrichtung, Konfiguration und Verbindung eines selbst-gehosteten Runners auf einem Mac mini zur Ausführung von macOS-Pipelines.

Voraussetzungen

Bevor Sie beginnen, stellen Sie sicher, dass Sie haben:

  • Einen Mac mini (registrieren Sie sich bei Macfleet)
  • Ein GitHub-Repository mit Administratorrechten
  • Einen installierten Paketmanager (vorzugsweise Homebrew)
  • Git auf Ihrem System installiert

Schritt 1: Ein dediziertes Benutzerkonto erstellen

Erstellen Sie zunächst ein dediziertes Benutzerkonto für den GitHub Actions Runner:

# Das 'gh-runner' Benutzerkonto erstellen
sudo dscl . -create /Users/gh-runner
sudo dscl . -create /Users/gh-runner UserShell /bin/bash
sudo dscl . -create /Users/gh-runner RealName "GitHub runner"
sudo dscl . -create /Users/gh-runner UniqueID "1001"
sudo dscl . -create /Users/gh-runner PrimaryGroupID 20
sudo dscl . -create /Users/gh-runner NFSHomeDirectory /Users/gh-runner

# Das Passwort für den Benutzer setzen
sudo dscl . -passwd /Users/gh-runner ihr_passwort

# 'gh-runner' zur 'admin'-Gruppe hinzufügen
sudo dscl . -append /Groups/admin GroupMembership gh-runner

Wechseln Sie zum neuen Benutzerkonto:

su gh-runner

Schritt 2: Erforderliche Software installieren

Installieren Sie Git und Rosetta 2 (wenn Sie Apple Silicon verwenden):

# Git installieren, falls noch nicht installiert
brew install git

# Rosetta 2 für Apple Silicon Macs installieren
softwareupdate --install-rosetta

Schritt 3: Den GitHub Actions Runner konfigurieren

  1. Gehen Sie zu Ihrem GitHub-Repository
  2. Navigieren Sie zu Einstellungen > Actions > Runners

GitHub Actions Runner

  1. Klicken Sie auf "New self-hosted runner" (https://github.com/<username>/<repository>/settings/actions/runners/new)
  2. Wählen Sie macOS als Runner-Image und ARM64 als Architektur
  3. Folgen Sie den bereitgestellten Befehlen, um den Runner herunterzuladen und zu konfigurieren

GitHub Actions Runner

Erstellen Sie eine .env-Datei im _work-Verzeichnis des Runners:

# _work/.env Datei
ImageOS=macos15
XCODE_15_DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
  1. Führen Sie das run.sh-Skript in Ihrem Runner-Verzeichnis aus, um die Einrichtung abzuschließen.
  2. Überprüfen Sie, dass der Runner aktiv ist und auf Jobs im Terminal wartet, und überprüfen Sie die GitHub-Repository-Einstellungen für die Runner-Zuordnung und den Idle-Status.

GitHub Actions Runner

Schritt 4: Sudoers konfigurieren (Optional)

Wenn Ihre Actions Root-Privilegien benötigen, konfigurieren Sie die sudoers-Datei:

sudo visudo

Fügen Sie die folgende Zeile hinzu:

gh-runner ALL=(ALL) NOPASSWD: ALL

Schritt 5: Den Runner in Workflows verwenden

Konfigurieren Sie Ihren GitHub Actions Workflow, um den selbst-gehosteten Runner zu verwenden:

name: Beispiel-Workflow

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: [self-hosted, macOS, ARM64]
    steps:
      - name: NodeJS installieren
        run: brew install node

Der Runner ist bei Ihrem Repository authentifiziert und mit self-hosted, macOS und ARM64 markiert. Verwenden Sie ihn in Ihren Workflows, indem Sie diese Labels im runs-on-Feld angeben:

runs-on: [self-hosted, macOS, ARM64]

Best Practices

  • Halten Sie Ihre Runner-Software auf dem neuesten Stand
  • Überwachen Sie regelmäßig Runner-Logs auf Probleme
  • Verwenden Sie spezifische Labels für verschiedene Runner-Typen
  • Implementieren Sie angemessene Sicherheitsmaßnahmen
  • Erwägen Sie die Verwendung mehrerer Runner für Lastverteilung

Fehlerbehebung

Häufige Probleme und Lösungen:

  1. Runner verbindet sich nicht:

    • Überprüfen Sie die Netzwerkverbindung
    • Überprüfen Sie die Gültigkeit des GitHub-Tokens
    • Stellen Sie angemessene Berechtigungen sicher
  2. Build-Fehler:

    • Überprüfen Sie die Xcode-Installation
    • Überprüfen Sie erforderliche Abhängigkeiten
    • Überprüfen Sie Workflow-Logs
  3. Berechtigungsprobleme:

    • Überprüfen Sie Benutzerberechtigungen
    • Überprüfen Sie sudoers-Konfiguration
    • Überprüfen Sie Dateisystem-Berechtigungen

Fazit

Sie haben jetzt einen selbst-gehosteten GitHub Actions Runner auf Ihrem Mac mini konfiguriert. Diese Einrichtung bietet Ihnen mehr Kontrolle über Ihre CI/CD-Umgebung und ermöglicht es Ihnen, macOS-spezifische Workflows effizient auszuführen.

Denken Sie daran, Ihren Runner regelmäßig zu warten und ihn mit den neuesten Sicherheitspatches und Software-Versionen auf dem neuesten Stand zu halten.

Native App

Macfleet native App

Macfleet Installationsanleitung

Macfleet ist eine leistungsstarke Flottenmanagement-Lösung, die speziell für Cloud-gehostete Mac Mini-Umgebungen entwickelt wurde. Als Mac Mini Cloud-Hosting-Anbieter können Sie Macfleet verwenden, um Ihre gesamte Flotte virtualisierter Mac-Instanzen zu überwachen, zu verwalten und zu optimieren.

Diese Installationsanleitung führt Sie durch die Einrichtung der Macfleet-Überwachung auf macOS-, Windows- und Linux-Systemen, um eine umfassende Übersicht über Ihre Cloud-Infrastruktur zu gewährleisten.

🍎 macOS

  • Laden Sie die .dmg-Datei für Mac hier herunter
  • Doppelklicken Sie auf die heruntergeladene .dmg-Datei
  • Ziehen Sie die Macfleet-App in den Anwendungsordner
  • Werfen Sie die .dmg-Datei aus
  • Öffnen Sie Systemeinstellungen > Sicherheit & Datenschutz
    • Datenschutz-Tab > Bedienungshilfen
    • Aktivieren Sie Macfleet, um Überwachung zu erlauben
  • Starten Sie Macfleet aus den Anwendungen
  • Die Verfolgung startet automatisch

🪟 Windows

  • Laden Sie die .exe-Datei für Windows hier herunter
  • Rechtsklick auf die .exe-Datei > "Als Administrator ausführen"
  • Folgen Sie dem Installationsassistenten
  • Akzeptieren Sie die Allgemeinen Geschäftsbedingungen
  • Erlauben Sie in Windows Defender, wenn aufgefordert
  • Gewähren Sie Anwendungsüberwachungsberechtigungen
  • Starten Sie Macfleet aus dem Startmenü
  • Die Anwendung beginnt automatisch mit der Verfolgung

🐧 Linux

  • Laden Sie das .deb-Paket (Ubuntu/Debian) oder .rpm (CentOS/RHEL) hier herunter
  • Installieren Sie mit Ihrem Paketmanager
    • Ubuntu/Debian: sudo dpkg -i Macfleet-linux.deb
    • CentOS/RHEL: sudo rpm -ivh Macfleet-linux.rpm
  • Erlauben Sie X11-Zugriffsberechtigungen, wenn aufgefordert
  • Fügen Sie den Benutzer zu entsprechenden Gruppen hinzu, falls erforderlich
  • Starten Sie Macfleet aus dem Anwendungsmenü
  • Die Anwendung beginnt automatisch mit der Verfolgung

Hinweis: Nach der Installation auf allen Systemen melden Sie sich mit Ihren Macfleet-Anmeldedaten an, um Daten mit Ihrem Dashboard zu synchronisieren.