#!/usr/bin/perl # getConsoleUsername: # This script echos the name of the currently active user # (this is useful when using Fast User Switching) # # This script also serves as an illustration of using the 'scutil' command. # Cameron Hayne (macdev@hayne.net) July 2008 use strict; use warnings; my $scutil = "/usr/sbin/scutil"; my $consoleUserKey = "State:/Users/ConsoleUser"; my $results = `echo "show $consoleUserKey" | $scutil`; #print $results; my ($uid) = $results =~ m/^\s*UID\s*:\s*(\d+)\s*$/m; my ($username) = $results =~ m/^\s*Name\s*:\s*(\S+)\s*$/m; #print "$uid\n"; print "$username\n";