Search code examples
macosapplescriptnsuserdefaultsuserdefaults

Isn't possible to store array of strings in defaults write?


I have a use-case where I have to store array of strings in defaults write but it seems like it is not working in applescript.

do shell script "defaults write com.subdomain.xyz -array \"abc\" \"abcd\" \"abcde\""

error

error "2022-06-17 13:47:40.780 defaults[5694:216572] Unexpected argument abcd; leaving defaults unchanged." number 1

Solution

  • You aren’t declaring a key. Here, I added the array name myNewArray as key:

    do shell script "defaults write com.subdomain.xyz myNewArray -array " & ¬
        "\"abc\" \"abcd\" \"abcde\""