Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Int values are not always recognized. #3

Open
lgarron opened this issue Dec 28, 2024 · 3 comments
Open

Int values are not always recognized. #3

lgarron opened this issue Dec 28, 2024 · 3 comments

Comments

@lgarron
Copy link

lgarron commented Dec 28, 2024

Repro on macOS 15.1.1:

  1. Run: plistwatch | grep -v "ContextStoreAgent"
  2. Open System Settings → Control Center → Menu Bar Only → Clock → Clock Options…
  3. Change the "Show date" dropdown value.
  4. Click "Done" and wait for the change to be written.

This writes a number to the plist, as can be verified by keeping ~/Library/Preferences/com.apple.menuextra.clock.plist open in Xcode.

However, plistwatch shows e.g.:

defaults write "com.apple.menuextra.clock" "ShowDate" '2'

Running this command will clobber the int value with a string and cause it to be effectively ignored by the OS (in this case).

Although I want to note that plistwatch has saved me a lot more time than it has cost me, this particular issue took me a few weeks to really understand and debug before I could fix it for good.

@pjg11
Copy link

pjg11 commented Jan 3, 2025

While the tool itself doesn't do this yet, you can add the type next to the number like so:

defaults write "com.apple.menuextra.clock" "ShowDate" -int '2'

This will get the number to be correctly recognized as an integer instead of a string.

I came across this issue while using the tool recently, so I tried implementing it (fork). It supports int, float, array and string for now.

@lgarron
Copy link
Author

lgarron commented Jan 4, 2025

While the tool itself doesn't do this yet, you can add the type next to the number like so:

Yeah, fortunately that's not too hard if you know that something is not meant to be written as a string.

What is an issue, though, is if the command implies that it can be run as-is for non-strings.

I just checked out your fork, and it seems to work well for me! I'll probably be using that for now, thanks! 🤩

@lgarron
Copy link
Author

lgarron commented Jan 8, 2025

I came across this issue while using the tool recently, so I tried implementing it (fork). It supports int, float, array and string for now.

On a second look, it looks like this is trying to establish the type by looking at the serialized value, which I don't think produces correct and secure results. I think using defaults read-type would be more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants