0

I am trying to edit a date value in a plist to todays date. I found a previous question on here relating to it, but i get an error every time.

Here is what i am using

defaults write com.test.name.plist TestAppFirstSeen $(date +"%Y-%m-%d %l:%M:%S +0000")

This is the error i get:

defaults[10761:276123] Unexpected argument 11:43:25; leaving defaults unchanged.

Any idea what i am doing wrong?

0
1

I'm surprised the original solution ever worked, but maybe the defaults command changed in recent versions. Try

defaults write com.test.name.plist TestAppFirstSeen "$(date +'%Y-%m-%d %l:%M:%S +0000')"

Also, %l gives you the hours between 1 and 12. If you want 1 to 24 use %H instead.

6
  • This works! Wonderful, thank you! Now i need to put it into a script so i can run it whenever, can i just paste that line into a shell script, save it and just double click the script?
    – hardtofin
    Apr 30 '20 at 14:44
  • So i have tried this as an apple script, but it doesn't work: do shell script "defaults write com.test.name.plist TestAppFirstSeen "$(date +'%Y-%m-%d %l:%M:%S +0000')" I think its something to do with having to put " at the start of the command, after "script" but i am not sure. It gives this error: A unknown token can’t go after this “"”.
    – hardtofin
    Apr 30 '20 at 15:17
  • @hardtofin Well, within AppleScript you probably need to escape the quotes within the command.
    – nohillside
    Apr 30 '20 at 15:26
  • I'm really sorry but i don't understand. I googled escape quotes and so now have: do shell script "defaults write com.test.name.plist TestAppFirstSeen \"$(date +'%Y-%m-%d %l:%M:%S +0000')" So there is a \ in front of the "$(date, but it still doesn't work. This is the error: sh: -c: line 0: unexpected EOF while looking for matching `"' sh: -c: line 1: syntax error: unexpected end of file
    – hardtofin
    Apr 30 '20 at 15:34
  • do shell script "defaults write com.test.name.plist TestAppFirstSeen \"$(date +'%Y-%m-%d %l:%M:%S +0000')\""
    – nohillside
    Apr 30 '20 at 15:49

You must log in to answer this question.

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