Getting the user id of the logged in user

For the launchctl terminal command I need to get the id of the logged in user. A

id -u username

does that. But which username should I use? My main computer has the users “Beatrix Willius” and “Beatrix_Willius”. The first one has a short username of beatrixwillius. The secone one is beatrixwillius 1 or beatrixwillius\ 1 when using “echo $HOME”.

I’ve been doing some tests in the Terminal:

Trixis-iMac:~ beatrix_willius$ id -u beatrixwillius\ 1

id: beatrixwillius 1: no such user

Trixis-iMac:~ beatrix_willius$ id -u beatrixwillius 1


Trixis-iMac:~ beatrix_willius$ id -u beatrix_willius


Trixis-iMac:~ beatrix_willius$ id -u 'beatrixwillius 1'

id: beatrixwillius 1: no such user

“beatrixwillius\ 1” doesn’t work. “beatrixwillius 1” gets the “Beatrix Willius” user and not “Beatrix_Willius” with the underscore.

beatrix_willius gets the correct user. There I got the username with SystemInformationMBS.ShortUsername and not “echo $HOME”. Is the ShortUsername safe to use?

IIRC it is 501 :slight_smile:

What does whoami say? Does that still work even?

Can you use Xojo code to get the UID of the current user?
In that case a simple declare works:

Declare Function getuid Lib "AppKit" () As Integer
Dim u As Integer = getuid()
Me.AddText "UID: "  + Str(u) + EndOfLine

otherwise you can just use

id -u

in Terminal to get the current user ID. There is no need for a name.

1 Like

@Sam_Rowlands : I always work with the second user because the automatic import screwed up my users.

@TomE: thanks, I misunderstood the instructions for launchctl that I read.