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

CFPreferences #1441

Open
cmsj opened this issue May 30, 2017 · 10 comments
Open

CFPreferences #1441

cmsj opened this issue May 30, 2017 · 10 comments

Comments

@cmsj
Copy link
Member

cmsj commented May 30, 2017

In researching #1437 it seems that a fair number of macOS system components work by setting preference values with CFPreferences API calls and NSDistributedNotification messages. We already support the latter, and adding the former doesn't look like it would be a huge amount of work.

@latenitefilms
Copy link
Contributor

Maybe #1441 & #1432 should be combined to offer a new hs.preferences extension that covers both basis?

@asmagill
Copy link
Member

asmagill commented Sep 1, 2017

@cmsj, In response to some questions raised in #1078, I have started on writing a module utilizing the CFPreferences to more accurately mirror defaults then hs.plist or hs.settings currently do. I hadn't seen this entry at that time; I hope to have something test worthy this weekend, but if you've already got something in the works, I can hold off... just let me know.

@latenitefilms
Copy link
Contributor

@asmagill - Awesome! For the sake of completeness, it would also be amazing to have edit functionality and NSKeyedArchiver support as discussed in #1498.

@asmagill
Copy link
Member

asmagill commented Sep 1, 2017

with the same caveats archived objects have in hs.pasteboard, I don't think that will be a problem

@latenitefilms
Copy link
Contributor

@asmagill Incredible. This is going to open up so many doors for us (as all of Final Cut Pro's Pasteboard data is organised using NSKeyedArchiver), if you can make this happen (as we've been dreading trying to write our own NSKeyedArchiver code in Lua) - so a MASSIVE thank you in advance!

@cmsj
Copy link
Member Author

cmsj commented Sep 1, 2017

@asmagill go for it, I haven't made any moves on this :)

@latenitefilms
Copy link
Contributor

I've been playing around with hs._asm.cfpreferences. It seems to read Preferences great - but writing to them, opens up some challenges.

If we use TextEdit as an example:

> hs.inspect(cfpreferences.applicationMap()["com.apple.TextEdit"])
{ "file:///Users/chrishocking/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/", "file:///Users/chrishocking/Library/Preferences/" }

It seems hs._asm.cfpreferences.getValue() and hs._asm.cfpreferences.setValue() only modify the ~/Library/Preferences/com.apple.TextEdit file, and not the sand-boxed ~/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit file - which is what TextEdit actually uses.

Maybe related? http://ddeville.me/2012/12/shared-preferences-between-sandboxed-applications

@latenitefilms
Copy link
Contributor

latenitefilms commented May 7, 2018

Actually, this works:

> cfpreferences.setValue("AppleLanguages", {"fr-FR"}, "/Users/chrishocking/Library/Containers/com.apple.TextEdit/Data/Library/Preferences/com.apple.TextEdit")

Source: https://stackoverflow.com/a/33264463

@latenitefilms
Copy link
Contributor

@asmagill - Not urgent, so please don't feel like you have to reply if you're absolutely flat out, but I was just wondering why we're seeing different results in Hammerspoon versus CommandPost? Any tips or ideas?

screen shot 2018-05-08 at 12 14 53 am

@latenitefilms
Copy link
Contributor

@asmagill - FYI: I'm seeing the following memory leak using hs._asm.cfpreferences:

screen shot 2018-08-13 at 7 32 04 pm

This seems to be where the problem lies - but I can't see anything obvious as it looks like you're already releasing everything?

https://github.com/asmagill/hammerspoon_asm/blob/master/cfpreferences/internal.m#L595

Any ideas?

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

No branches or pull requests

3 participants