rename_workstation_manual_macos.sh - limehawk/rmm-scripts GitHub Wiki
rename_workstation_manual_macos.sh
Renames a macOS device using a custom client segment with standardized naming pattern: CLIENT-USER-UUID.
Overview
This script renames a macOS device using a custom client segment override. Allows variable length client segment override. Sets HostName, ComputerName, and LocalHostName. Designed for RMM deployment.
Purpose
Renames a macOS device using a custom client segment override.
Naming Pattern (max 15 chars for NetBIOS compatibility): CLIENT-USERUUID CLIENT : Custom client segment (variable length, from $YourCustomClientHere) Falls back to $YourClientNameHere if custom not set USER : Sanitized username (maximized, truncated if needed) UUID : Hardware UUID tail (at least 3 chars)
Notes:
- Only A-Z, 0-9, and hyphen used
- Name never starts or ends with '-'
- Always exactly 15 chars
- Sets HostName, ComputerName, and LocalHostName
Prerequisites
- Root/sudo access required
- macOS 10.14 or later
- RMM variable $YourCustomClientHere or $YourClientNameHere must be set
Configuration
Required Inputs
- CUSTOM_CLIENT: RMM variable $YourCustomClientHere (variable length)
- CLIENT_NAME: Fallback RMM variable $YourClientNameHere
- MAX_HOST_LEN: Maximum hostname length (default: 15)
- MIN_UUID_LEN: Minimum UUID suffix length (default: 3)
Behavior
- Gets custom client segment from RMM variable (or falls back)
- Retrieves current logged-in user
- Gets hardware UUID from system
- Builds hostname: CLIENT-USER-UUID (exactly 15 chars)
- Sets HostName, ComputerName, and LocalHostName
- Flushes DNS cache
Security Notes
- No secrets exposed in output
- Runs with elevated privileges (sudo required)
Exit Codes
- 0 - Success
- 1 - Failure (missing inputs, rename failed)
Example Output
[ INPUT VALIDATION ]
--------------------------------------------------------------
Custom Client : CUSTOM
Client Segment (custom) : CUSTOM
[ SYSTEM VALUES ]
--------------------------------------------------------------
Console User : jsmith
User Segment : JSMITH
Hardware UUID : 12345678-ABCD-EFGH-IJKL-MNOPQRSTUVWX
UUID (clean) : 12345678ABCDEFGHIJKLMNOPQRSTUVWX
Current Hostname : Macintosh
[ BUILD HOSTNAME ]
--------------------------------------------------------------
Prefix : CUSTOM-
User Part : JSM
UUID Suffix : TUVWX
Desired Name : CUSTOM-JSMTUVWX
Name Length : 15
[ RENAME ACTION ]
--------------------------------------------------------------
Status : RENAMING TO CUSTOM-JSMTUVWX
Result : RENAME SUCCESSFUL
Action : Flushing DNS cache
[ FINAL STATUS ]
--------------------------------------------------------------
Hostname set to: CUSTOM-JSMTUVWX
HostName, ComputerName, and LocalHostName updated
[ SCRIPT COMPLETED ]
--------------------------------------------------------------
Version History
- 1.0.0 (November 2024) - Initial release
Links
- View Script Source
- Scripts - Back to script index