OS X的defaults命令如何访问沙盒应用程序的首选项? [英] How does OS X's defaults command get access to prefs of sandboxed apps?

查看:69
本文介绍了OS X的defaults命令如何访问沙盒应用程序的首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写首选项编辑器工具(请参阅 http://www.tempel.org/PrefsEditor ).它实际上是defaults命令的GUI版本.

I am writing a preferences editor tool (see http://www.tempel.org/PrefsEditor). It is effectively a GUI version of the defaults command.

不过,我在读取(更不用说编写)随机沙盒应用程序的首选项时遇到了麻烦.

I have trouble reading (let alone writing) preferences of random sandboxed applications, though.

例如,当我尝试获取Maps应用的键时,我得到的返回值为NULL:

For instance, when I try to get the keys of the Maps app, I get NULL returned:

CFArrayRef prefs = CFPreferencesCopyKeyList (CFSTR("com.apple.Maps"), kCFPreferencesCurrentUser, kCFPreferencesAnyHost);

但是,defaults命令能够读取这些首选项:

However, the defaults command is able to read those prefs:

defaults read com.apple.Maps

我想知道defaults命令是如何做到这一点的,试图在我的工具中做到这一点.

I like to know how the defaults command accomplishes this, trying to do the same in my tool.

推荐答案

尝试:

CFPropertyListRef prop = CFPreferencesCopyValue(CFSTR("ElementsVersion"),
CFSTR("/Users/karsten/Library/Containers/com.apple.Maps/Data/Library/Preferences/com.apple.Maps"),
CFSTR("kCFPreferencesCurrentUser"),
CFSTR("kCFPreferencesAnyHost"));

似乎您需要文件的路径,而不仅仅是bundle-id

seems you need the path to the file, not just the bundle-id

这篇关于OS X的defaults命令如何访问沙盒应用程序的首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆