dscl
It seems that the most promising method is to modify the JPEGPhoto
attribute for the user. The problem is, while the JPEG image can be converted very simply to a hex string, the value is too long to just pass at the command-line. This attribute seems to be what the GUI writes to when you drag in an image. Recovering the image from this variable when set is as simple as:
dscl . read /Users/username JPEGPhoto | xxd -r -p > ./username.jpg
The second common way mentioned on the forums is to:
dscl . delete /Users/username JPEGPhoto
dscl . delete /Users/username Picture
dscl . delete /Users/username Picture "/Library/User Pictures/username.jpg"
This only changes the 'login' icon and not the icon seen in the User detail page in System Preferences.
Using sysadminctl
When creating or managing users prefer sysadminctl
over the list of dscl
commands that are commonly mentioned in forums. sysadminctl
sets the user up correctly with a SECURE TOKEN which is important if you want to use FileVault
the user should be able to unlock the disk at boot. It also offers the ability to set the user image when created. Unfortunately it doesn't offer the ability to change user images.
Using dsimport
What does work for changing the user image is dsimport
.
The script usage is:
./change_userpic.sh USERNAME /path/to/image/jpg
GIST
#!/bin/bash
declare -xr AWK_CMD="/usr/bin/awk"
declare -xr SW_VERS_CMD="/usr/bin/sw_vers"
declare -xr DSIMPORT_CMD="/usr/bin/dsimport"
declare -xr ID_CMD="/usr/bin/id"
USERNAME="$1"; export USERNAME
USERPIC="$2"; export USERPIC
OSVERSION=$(${SW_VERS_CMD} -productVersion | ${AWK_CMD} -F"." '{print $2;exit}'); export OSVERSION
# Add the LDAP picture to the user record if dsimport is avaiable 10.6+
if [ -f "${USERPIC}" ] ; then
# On 10.6 and higher this works
if [ "${OSVERSION}" -ge "6" ] ; then
declare -x MAPPINGS='0x0A 0x5C 0x3A 0x2C'
declare -x ATTRS='dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto'
declare -x PICIMPORT="/Library/Caches/${USERNAME}.picture.dsimport"
printf "%s %s \n%s:%s" "${MAPPINGS}" "${ATTRS}" "${USERNAME}" "${USERPIC}" >"${PICIMPORT}"
# Check to see if the username is correct and import picture
if ${ID_CMD} "${USERNAME}" &>/dev/null ; then
# No credentials passed as we are running as root
${DSIMPORT_CMD} "${PICIMPORT}" /Local/Default M &&
echo "Successfully imported users picture."
fi
fi
fi
Removing the file's extension should cause the file to open in your default terminal application. Alternately, you could select "All Applications" from the "Enable" menu in the "Open With" dialog to enable opening with "Terminal.app" regardless of the file's extension.
Best Answer
This is simple you can ua the following ways:
command | tee output.txt
The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, it gets overwritten.
command | tee -a output.txt
The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.
If you want any to know where I got this here is the reference:https://askubuntu.com/questions/420981/how-do-i-save-terminal-output-to-a-file/420983 @Byte Commamder.