Add a keychain to search list?
keychain, macos
Solution
A one line version of @mles solution above:
`security list-keychains -d user -s $(security list-keychains -d user | sed -e s/\"//g) <new keychain>`
The issue with directly piping in the output of `security list-keychains -d user` is it surrounds the results with quotes. Solution uses `sed` to strip them out.
Problem
I need to add a .keychain file to my keychains search list for some automated build tools. Currently I'm using `security list-keychains` command: ``` list-keychains [-h] [-d user|system|common|dynamic] [-s [keychain...]] Display or manipulate the keychain search list. ``` This command let's you set the entire keychain search list, but it does not provide a way to simply add another keychain. So adding a keychain becomes a 2 step process. - Run list-keychains and parse the output - Then do something like `list-keychains -s ${existing_chains} ${new_keychain}` While this works, it seems overly complicated and introduces a race condition. Also it seems like `open my.keychain` will add it to the search list, but I tend to avoid using commands like `open` in scripting or headless environments. Is there a simpler or better way to add a keychain to the search list?