Skip to content

Instantly share code, notes, and snippets.

@IMMarkXLII
Forked from palmerc/userpic.sh
Last active August 24, 2020 19:29
Show Gist options
  • Select an option

  • Save IMMarkXLII/99d58d309a5a04211c8d254f284546a6 to your computer and use it in GitHub Desktop.

Select an option

Save IMMarkXLII/99d58d309a5a04211c8d254f284546a6 to your computer and use it in GitHub Desktop.

Revisions

  1. Ashish Adhikari revised this gist Mar 20, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions change_user_account_picture.sh
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,7 @@ if [ -f "${USERPIC}" ] ; then
    # 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
    # removing the current image from user Pictures using dscl
    dscl . -delete /Users/${USERNAME} JPEGPhoto &&
    dscl . delete /Users/${USERNAME} Picture &&
    ${DSIMPORT_CMD} "${PICIMPORT}" /Local/Default M &&
  2. Ashish Adhikari renamed this gist Mar 20, 2020. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion userpic.sh → change_user_account_picture.sh
    Original file line number Diff line number Diff line change
    @@ -20,8 +20,10 @@ if [ -f "${USERPIC}" ] ; then
    # 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
    dscl . -delete /Users/${USERNAME} JPEGPhoto &&
    dscl . delete /Users/${USERNAME} Picture &&
    ${DSIMPORT_CMD} "${PICIMPORT}" /Local/Default M &&
    echo "Successfully imported users picture."
    fi
    fi
    fi
    fi
  3. @palmerc palmerc revised this gist Aug 27, 2019. 1 changed file with 22 additions and 21 deletions.
    43 changes: 22 additions & 21 deletions userpic.sh
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,27 @@
    #!/bin/bash
    declare -xr awk="/usr/bin/awk"
    declare -xr sw_vers="/usr/bin/sw_vers"
    declare -xr dsimport="/usr/bin/dsimport"
    declare -xr id="/usr/bin/id"

    export UserName="$1"
    export UserPicture="/path/to/$UserName.jpg"
    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"

    export OsVersion=`$sw_vers -productVersion | $awk -F"." '{print $2;exit}'`
    # Add the LDAP picture to the user record if dsimport is avaiable 10.6+
    if [ -f "$UserPicture" ] ; then
    # On 10.6 and higher this works
    if [ "$OsVersion" -ge "6" ] ; then
    declare -x Mappings='0x0A 0x5C 0x3A 0x2C'
    declare -x Attributes='dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto'
    declare -x PictureImport="/Library/Caches/$UserName.picture.dsimport"
    printf "%s %s \n%s:%s" "$Mappings" "$Attributes" "$UserName" "$UserPicture" >"$PictureImport"
    # Check to see if the username is correct and import picture
    if $id "$UserName" &>/dev/null ; then
    # No credentials passed as we are running as root
    $dsimport -g "$PictureImport" /Local/Default M &&
    echo "Successfully imported users picture."
    fi
    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
  4. @acidprime acidprime revised this gist Mar 21, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion userpic.sh
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,9 @@ declare -xr dsimport="/usr/bin/dsimport"
    declare -xr id="/usr/bin/id"

    export UserName="$1"
    export UserPicture="/path/to/$UserName.jpg"

    export OsVersion=`$sw_vers -productVersion | $awk -F"." '{print $2;exit}'`
    declare -x UserPicture="/path/to/$UserName.jpg"
    # Add the LDAP picture to the user record if dsimport is avaiable 10.6+
    if [ -f "$UserPicture" ] ; then
    # On 10.6 and higher this works
  5. @acidprime acidprime revised this gist Mar 21, 2012. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions userpic.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,11 @@
    #!/bin/bash
    declare -xr awk="/usr/bin/awk"
    declare -xr sw_vers="/usr/bin/sw_vers"
    declare -xr dsimport="/usr/bin/dsimport"
    declare -xr id="/usr/bin/id"

    export UserName="$1"
    export OsVersion=`sw_vers -productVersion | awk -F"." '{print $2;exit}'`
    export OsVersion=`$sw_vers -productVersion | $awk -F"." '{print $2;exit}'`
    declare -x UserPicture="/path/to/$UserName.jpg"
    # Add the LDAP picture to the user record if dsimport is avaiable 10.6+
    if [ -f "$UserPicture" ] ; then
    @@ -10,9 +16,9 @@ export OsVersion=`sw_vers -productVersion | awk -F"." '{print $2;exit}'`
    declare -x PictureImport="/Library/Caches/$UserName.picture.dsimport"
    printf "%s %s \n%s:%s" "$Mappings" "$Attributes" "$UserName" "$UserPicture" >"$PictureImport"
    # Check to see if the username is correct and import picture
    if id "$UserName" &>/dev/null ; then
    if $id "$UserName" &>/dev/null ; then
    # No credentials passed as we are running as root
    dsimport -g "$PictureImport" /Local/Default M &&
    $dsimport -g "$PictureImport" /Local/Default M &&
    echo "Successfully imported users picture."
    fi
    fi
  6. @acidprime acidprime revised this gist Mar 21, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions userpic.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    export UserName="$1"
    export OsVersion=`sw_vers -productVersion | awk -F"." '{print $2;exit}'`
    declare -x UserPicture="/path/to/$UserName.jpg"
    # Add the LDAP picture to the user record if dsimport is avaiable 10.6+
  7. @acidprime acidprime revised this gist Mar 20, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion userpic.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    export OsVersion=`$sw_vers -productVersion | $awk -F"." '{print $2;exit}'`
    export OsVersion=`sw_vers -productVersion | awk -F"." '{print $2;exit}'`
    declare -x UserPicture="/path/to/$UserName.jpg"
    # Add the LDAP picture to the user record if dsimport is avaiable 10.6+
    if [ -f "$UserPicture" ] ; then
  8. @acidprime acidprime created this gist Mar 20, 2012.
    18 changes: 18 additions & 0 deletions userpic.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    export OsVersion=`$sw_vers -productVersion | $awk -F"." '{print $2;exit}'`
    declare -x UserPicture="/path/to/$UserName.jpg"
    # Add the LDAP picture to the user record if dsimport is avaiable 10.6+
    if [ -f "$UserPicture" ] ; then
    # On 10.6 and higher this works
    if [ "$OsVersion" -ge "6" ] ; then
    declare -x Mappings='0x0A 0x5C 0x3A 0x2C'
    declare -x Attributes='dsRecTypeStandard:Users 2 dsAttrTypeStandard:RecordName externalbinary:dsAttrTypeStandard:JPEGPhoto'
    declare -x PictureImport="/Library/Caches/$UserName.picture.dsimport"
    printf "%s %s \n%s:%s" "$Mappings" "$Attributes" "$UserName" "$UserPicture" >"$PictureImport"
    # Check to see if the username is correct and import picture
    if id "$UserName" &>/dev/null ; then
    # No credentials passed as we are running as root
    dsimport -g "$PictureImport" /Local/Default M &&
    echo "Successfully imported users picture."
    fi
    fi
    fi