macOS: retrieve keychain's item's password and username with `security find-internet-password`

-1

I would like to retrieve my appstoreconnect.apple.com username and password from macOS Keychain, to write a script with those credentials afterwards. When I type security find-internet-password -s "appstoreconnect.apple.com" -g i get

keychain: "/Users/me/Library/Keychains/login.keychain-db"
version: 512
class: "inet"
attributes:
    0x00000007 <blob>="appstoreconnect.apple.com"
    0x00000008 <blob>=<NULL>
    "acct"<blob>="my-username"
    "atyp"<blob>="dflt"
    "cdat"<timedate>=0x32303230303731363133343131315A00  "20200716134111Z\000"
    "crtr"<uint32>=<NULL>
    "cusi"<sint32>=<NULL>
    "desc"<blob>=<NULL>
    "icmt"<blob>=<NULL>
    "invi"<sint32>=<NULL>
    "mdat"<timedate>=0x32303230303731363133343533395A00  "20200716134539Z\000"
    "nega"<sint32>=<NULL>
    "path"<blob>="/"
    "port"<uint32>=0x00000000
    "prot"<blob>=<NULL>
    "ptcl"<uint32>="htps"
    "scrp"<sint32>=<NULL>
    "sdmn"<blob>=<NULL>
    "srvr"<blob>="appstoreconnect.apple.com"
    "type"<uint32>=<NULL>
password: "my-password"

how, from that, can I retrieve my-username and my-password values, to use as variables in my shell script ?

macos
shell
keychain
asked on Stack Overflow Jul 16, 2020 by arnaudambro • edited Jul 16, 2020 by Marcin Orlowski

1 Answer

0

try

security find-internet-password -s "appstoreconnect.apple.com" -g | grep -E "acct|password" |  rev  | cut -d'"' -f2 |  rev
answered on Stack Overflow Jul 16, 2020 by Digvijay S

User contributions licensed under CC BY-SA 3.0