Applescript for setting the user profile picture in Mavericks

Hi all,

I have only basic knowledge of applescript, but have successfully created a few scripts in the past. I’m now trying to do an applescript for setting the user profile picture in Mavericks (10.9.4). I have the following script:


tell application "System Events"
 get the properties of the current user
 set the picture path of current user to alias "Mac OS X:Library:User Pictures:Flowers:custom.tif"
end tell

This doesn’t work (though I was told it does on previous versions of Mac OS X. It seems that in Mavericks, the properties of the ‘picture path’ is returned blank as “”.

Does anyone know a simple way to set the profile pic of the current user like this?

Thanks in advance!

sb

Hi seanboy50,

I’ve never changed the user picture, but an old trick to change a file when you can’t change the the reference is to swap out the file. i.e. you use the same path to some dummy name and replace that dummy file with a new picture file. I might try this, but I really hate fooling around with login stuff.

gl,
kel

Hey SB,

Change the image paths to suit, and give this a try.


set pic1 to "~/Pictures/iPhoto Library/Masters/2004/Female/Cobra.jpg"
set pic2 to alias ((path to pictures folder as text) & "Downloads (New):Sasha Luss:Sasha Luss 01.jpg")

tell application "System Events"
	picture path of current user
	
	tell current desktop
		set getMyDesktopPicture to get picture
		set picture to pic1
		set picture to pic2
	end tell
end tell

A bit late perhaps, but here is a script that should do what you want. It uses the shell command dscl to change the picture. As written it will ask you to select the picture you want to use, but it is easily changed to use a hard-coded file reference. You will need to enter an administrator’s password when prompted.

--
--	About user pictures:
--	A new user has an attribute 'Picture', but not 'JPEGPhoto'.
--	The JPEGPhoto attribute ignores transparency, so the picture displays in a white rectangle.
--	When you set a new user picture thru System Preferences it is stored in 'JPEGPhoto', but 'Picture' is not changed.
--	So, when you delete JPEGPhoto to get transparency respected, the actual picture reverts to Picture.
--	Sadly, the picture's path cannot be read from JPEGPhoto.
--	Note that transparency is a property of the picture itself, so this won't always yield the desired result.
--	See http://hints.macworld.com/article.php?story=20080328141726511
--
tell application "System Events" to set theUser to name of current user

set pic_container to (path to library folder from local domain as text) & "User Pictures:"
set newPic to choose file default location alias pic_container of type {"tif", "gif", "png"} with prompt "Select picture:"
-- note: I think that in 10.4 you had to use the value in kMDItemContentType for 'type'
set newPic_path to POSIX path of newPic
-- must read current value in order to change it
-- some minor jumping thru hoops to get actual path
set currentPic_path to text 2 thru end of 2nd paragraph of (do shell script "dscl . -read /users/" & theUser & " Picture")
-- change it
set theCommand to "dscl . -change /users/" & theUser & " Picture " & quoted form of currentPic_path & space & quoted form of newPic_path
do shell script theCommand with administrator privileges
-- and delete JPEGPhoto
set theCommand to "dscl . -delete /users/" & theUser & " JPEGPhoto"
do shell script theCommand with administrator privileges