applescriptsystem-preferencesdscl

strange property result for picture path of the current user in applescript


When I run:

tell application "System Events"
   get the properties of the current user
end tell

in applescript, everything looks fine except for the picture path. The path referenced is not what I see as my user picture.

I am probably missing something here, but I do not know what. Does the picture in the path referenced serve another purpose than the picture that I set to be my User Picture in System Preferences?

Thanks!


Solution

  • In short
    account image is 'JPEGPhoto' attribute of user record and get the properties of the current user is returning 'Picture' attribute of user record.

    Mac OS X 10.5+ stores user's account pictures within the Directory Service. User account contains a 'Picture'(that is a path to the account pictures) and 'JPEGPhoto' attribute in their user record .This can be read using the dscl command (dscl . -read /Users/username Picture and dscl . -read /Users/username JPEGPhoto | tail -1 | xxd -r -p > /accountImage.jpg).(initially both are same)

    If a user has modified their user picture at any time using system preferences the account picture is stored in the 'JPEGPhoto' attribute of their user record not in 'Picture' attribute.

    If a user has modified their user picture at any time using applescript the account picture is stored in the 'Picture' attribute of their user record not in 'JPEGPhoto' attribute.

    tell application "System Events"
        set the picture path of current user to "/Library/User Pictures/Flowers/Dahlia.tif"
    end tell  
    

    Your applescript is returning 'Picture' attribute of user record.

    Reference:
    Where does the Mac store account pictures?