Posted on 11-23-2016 09:28 AM
Like the title states, I would like to remove all keychain items with the same label. Here is how I am able to one at a time:
security delete-generic-password -l Wired 802.1X
A command I found on this forum uses an AWK command but im stuck there. Here is what I tried:
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
keychainItem=$( security dump-keychain /Library/Keychains/system.keychain | grep 'Wired 802.1X' | awk -F'["|"]' '/blob/{print $2}' )
security delete-generic-password /Library/Keychains/system.keychain -l "$keychainItem"
With output:
keychain: "/Library/Keychains/System.keychain"
version: 256
class: "genp"
attributes:
0x00000007 <blob>="Wired 802.1X"
0x00000008 <blob>=<NULL>
"acct"<blob>=<NULL>
"cdat"<timedate>=0x32303135303731333132333830365A00 "20150713123806Z00"
"crtr"<uint32>=<NULL>
"cusi"<sint32>=<NULL>
"desc"<blob>="802.1X Password"
"gena"<blob>=<NULL>
"icmt"<blob>=<NULL>
"invi"<sint32>=<NULL>
"mdat"<timedate>=0x32303135303731333132333830365A00 "20150713123806Z00"
"nega"<sint32>=<NULL>
"prot"<blob>=<NULL>
"scrp"<sint32>=<NULL>
"svce"<blob>="com.apple.network.eap.system.item.profileid.8CBE717B-BC16-4DCF-AC34-5E329FB6C337"
"type"<uint32>=<NULL>
password has been deleted.
Posted on 11-23-2016 05:43 PM
Got it figured out with the help from other forums. Here are two ways of doing it if anyone interested!
First way is using AppleScript by repeating the command until error comes us then stops repeating:
repeat
if (do shell script "security delete-generic-password -l test > /dev/null 2>&1 &" with administrator) is "security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain." then exit repeat
end repeat
Second way is a regular command:
while security delete-generic-password -l DEMO >/dev/null
do true; done