I want to get the nickname of the currently logged in OS X user via Apple Script. Currently can only retrieve the full name or the nickname of a contact, I wasn't able to combine the two scripts.

tell application "System Events"
    get full name of current user
end tell

Returns my full name.

tell application "Contacts" to get nickname of person "My Name"

Returns my nickname.

I'd like to get the nickname of the vcard of the currently logged in user.


I've managed to solve it quite o.k.

tell application "Contacts"
    tell application "System Events"
        set theName to full name of current user
    end tell
    set theNick to nickname of person theName
    if theNick is not missing value then
        return theNick
        return word 1 of theName
    end if
end tell

It would be better to select the vcard associated with the user account and not just match the name. But I couldn't find out how to do this.


By nickname do you mean the short user name of the logged in user? Nickname seems to be only available in contacts and the user might not have set his contact card. You can get short user name by getting system info

set _info to system info
set _nickname to short user name of _info

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .