Trying to add a Space in front of the User Account Name

jesse_wilson
New Contributor II

Where I work we have a few Accounts that we want in front of the Students accounts. To do this we need to add a space in front of the Account we are creating. The script that was created by someone that is no longer here does not seems to work any more. We are using 10.9, 10.10 & 10.11.

From what I have found this should work but does not. I have also seen -realname & RealName but neither work. I do not want to change the Home Folder name, just the Full Name/Real Name.

dscl . -change /Users/$ShortName RealName "$FullName2" "$ShortName"

With this I have changed it to the following:
dscl . -change /Users/test RealName "Test" " Test"

dscl . -change /Users/test -realname "Test" " Test"

The script we use to use is as follows:
sudo dscl . -change /Users/imaginglearning -realname "Imagine Learning" " Imagine Learning"

Here is the error I get in Casper after trying to apply the script:
Script exit code: 185
Script result: DS Error: -14009 (eDSUnknownNodeName)
change: Invalid Path
Error running script: return code was 185.

12 REPLIES 12

andrew_nicholas
Valued Contributor

I don't think this functionality is possible by design. If you try editing an accounts shortname within System Preferences, you are unable to add a space at the front but can add another character. You might have to revisit the naming scheme

Picture for reference of editable options:dde139e2c1914a6dbd94569a0d7cefdf

jesse_wilson
New Contributor II

I was not the person that did it initially but I am trying to get it to work with another account. One account still does it properly. I cloned the policy and edited the scripts to for this other account that is needed for younger kids so they can quickly located it and click on it.

I can do that and it does work. The problem is that I have a few hundred laptops to do it on. It would take forever to do that on each one.

andrew_nicholas
Valued Contributor

Is the problem more likely in the variable $ShortName? It's called twice in "dscl . -change /Users/$ShortName RealName "$FullName2" "$ShortName" but the second call doesn't include the space. might it be better to use "dscl . -change /Users/$ShortName RealName "$FullName2" " $FullName2"?

jesse_wilson
New Contributor II

Everything I find online is for Renaming the UserName and the Folder Name. I do NOT want to change the Folder Name. I just want to Modify the User Name on the Login Screen so it will be in front of ALL the other Network Usernames on the Login Screen.

I have only been working with Apple computers for about two years so I am still learning. Do I need to tell it what the $FullName & $ShortName is supposed to be first.

$ShortName = "shortname"
$FullName = "fullname"

I have created some scripts for other things and have had them work, but not this one. The person that created it before is gone as I said and I am trying to get some of these old scripts.

When I use just $ShortName and $FullName I get the following error:

change: Invalid Path
<dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)

(Is this because I am doing it from bring logged in another account (Admin) and not from Root so it finds the correct user?)

The Script that was used before (above) does not work any more.

jesse_wilson
New Contributor II

I just tried this following command:

dscl . -change /Users/useraccount RealName "User Account" " User Account"

I get the following message:

<main> attribute status: eDSPermissionError
<dscl-cmd> DS Error: -14120 (sDSPermissionError)

Because of this I am sure I just needed to use sudo in front of it so I tried it again.

sudo dscl . -change /Users/useraccount RealName "User Account" " User Account"

After this I get the following message:

<main> attribute status: eDSAttributeNotFound
<dscl_cmd> DS Error: -14134 (eDSAttributeNotFound)

AVmcclint
Honored Contributor

What if you try a visible character instead of a space? Something like "_user" instead of " user" might be better for handling in scripts or su commands. Do the dscl commands take that instead?

su user
su  user
su   user
su     user

Is there really a difference between any of those commands? In order to be completely clear on what's passed to commands, I'd suggest less ambiguity.

jesse_wilson
New Contributor II

Because I am still new to all of this how would I use su or su user to rename a User Account from "Jesse" to " Jesse"? This is mainly set up for the younger kids that are getting to learn how to use a laptop. The space is being used in the account name to help them find this account quickly.

I tried the following but no success:

su dscl . -change /Users/jesse RealName "Jesse" " Jesse"

Message:

su: Sorry

dscl is not a command

I guess I would have to use su jesse but not sure what to do after that.

AVmcclint
Honored Contributor

I'm not sure I understand the purpose of what you're trying to do. Here's what I think I got now:

  1. you're using local accounts
  2. you only want to change the way the name is displayed on the login screen? 2a. or do you also want to change the way the home folders are displayed in /Users/ ?
  3. the users will never be doing anything in Terminal that would require them to specify the difference between "Jessie" and " Jessie"

Are my assumptions correct?
How many computers are you wanting to do this to?
How many user accounts on each computer are you wanting to do this to?
Will this be a recurring task you'll need to do over and over for new accounts?

If my assumptions are correct and you only want to change the name that is displayed in the Login Window, and you only have a handful of accounts to worry about, then you can easily change this in System preferences > Users & Groups by unlocking the preference pane and then right-clicking on the account and choose Advanced Options. If you want to change more than just the name that's displayed, I think you might be making it more complex than it needs to be.

jesse_wilson
New Contributor II

I work for a School.

1) The one I am wanting to change is a local account. There are two more local account (one hidden) and the rest that show up are Network Accounts.

2) I want it to change the way the name is displayed on the login screen.

3) The users should never need to use the terminal for any reason.

We have a few hundred laptops this account has to be added to. It would take a long time to do this individually on each computer specially they are all deployed to their schools with out the space in the front of the account name. We have over 2000 computers total we manage.

There are only two accounts this need to be done to. One is built in the image but the one I am trying to do does not need to be on every computer.

This is why I am trying to create policy with a script so it can be done after the laptop is imaged.

jesse_wilson
New Contributor II

Ok this is what I have done so far. If I repeat anything it is to try and explain what I tried and the out come.

open the terminal on a laptop that I want the Login User Name to change by adding a space to the front of the User Name.

sudo dscl . -change /Users/jesse RealName "Jesse" " Jesse"

If I type the above in the terminal on the computer I want to have the name changed on it works great.
If I type it in a second time I get the following message:

<main> attribute status: eDSAttributeNotFound
<dscl_cmd> DS Error: -14134 (eDSAttributeNotFound)

But if I put it in a sh file and push it through a policy I get the following error:

Script exit code: 185
Script result: DS Error: -14009 (eDSUnknownNodeName)
change: Invalid Path
Error running script: return code was 185.

So I tried adding killall cfprefsd to see if that would help. The reason I tried this is when I typed
sudo dscl . -change /Users/jesse RealName "Jesse" " Jesse" in the terminal with the System Preference open and went to Users & Groups nothing changed but when I closed the System Preferences and reopened it the space was added. If I have the System Preferences closed and open it after the bold line in this paragraph was entered in the Terminal the name is changed from "Jesse" to " Jesse" minus the "s. Now that the killall cfprefsd is added I get the following message in Casper:

Script exit code: 0
Script result: DS Error: -14009 (eDSUnknownNodeName)
change: Invalid Path

I am getting closer. Just need to figure out how to get it to work with the script. Without the "killall cfprefsd" the script fails in Casper but with it in the script is says complete other than the DS Error: -14009 (eDSUnknownNodeName).

So to make sure it is understood the outcome I am getting now so far:
If I type the sudo code in the terminal on the laptop that I want the name changed it works.
If I put that same code in a script it will not work, but no Script Exit code any more just the DS Error.

Again sorry for all the repeats in my posting. Just trying to make it easier to understand what I am trying. Thanks for all your help so far. Hope to pinpoint it soon and get away from this...lol

jesse_wilson
New Contributor II

Here is my code. I have tried both #!/bin/bash & #!/bin/sh

#!/bin/bash
## RenameJesseWilsonAccount

## Puts a space in front of the Full Name " Jesse Wilson"
sudo dscl . -change /Users/jessewilson RealName "Jesse Wilson" " Jesse Wilson"

killall cfprefsd

jesse_wilson
New Contributor II

I have no idea what had changed but it is now working. Thanks for all of your help and suggestions.

#!/bin/sh
## Rename Jesse Wilson Account

## Puts a space in front of the Full Name " Jesse Wilson"
sudo dscl . -change /Users/jessewilson RealName "Jesse Wilson" " Jesse Wilson"

killall cfprefsd