Application username ?

BlitzMax Forums/BlitzMax Beginners Area/Application username ?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This may only be relevant on OS X, but is there an easier way to get at the username of the person running the application ?

I want to persist a user preference file in /Users/*username*/Library/Application Support/*appname*/ but would need to extract the current username if I'm to do this and support multiple users.

Here's a workaround I've done but it's not ideal <grin>


Local appUser:String = getOSXUser()
Print appUser
End

' ------------------------------------------------
' Get OS X application user (in a roundabout way)
' ------------------------------------------------
Function getOSXUser:String()

    Local username:String = Null

    Local usersDir:String[] = LoadDir("/Users")
    ' iterate through each user dir
    For Local dirName:String = EachIn usersDir
        If Left(dirName,1) <> "." And dirName <> "Shared"
            ' *should* be a valid user dir
            ' try & change dir to a restricted dir
            dirIsReadable = ChangeDir("/Users/"+dirName+"/Library")
            If dirIsReadable
                username = dirName
                Exit
            End If
        End If
    Next

    Return username

End Function



Any ideas ?

try:
Print getenv_("USER")


under windows it's
Print getenv_("USERNAME")


Thanks Perturbatio

getenv_("USER") works great. Was searching all over for something like that but couldn't find it in the docs or the wiki.

yeah, getenv_ is part of the pub.stdc module I believe. but not documented.