Reading Mac defaults?

xuanbao · · 400 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hello,</p> <p>I&#39;m fairly new to this (and am not an engineer by trade) so apologies if this info was readily available and I just wasn&#39;t googling for the right thing.</p> <p>I need to read some values of the user&#39;s defaults settings in Mac.</p> <p>There is a package readily available to read the registry in Windows: <a href="https://godoc.org/golang.org/x/sys/windows/registry" rel="nofollow">https://godoc.org/golang.org/x/sys/windows/registry</a></p> <p>But I can&#39;t find an analogous version for Mac. </p> <p>I see there&#39;s a sys/unix: <a href="https://godoc.org/golang.org/x/sys/unix" rel="nofollow">https://godoc.org/golang.org/x/sys/unix</a></p> <p>But I don&#39;t see where/how you would read the defaults within that long list of functions. Any help is much appreciated.</p> <hr/>**评论:**<br/><br/>icholy: <pre><p>My &#34;they&#39;re writing malware&#34; senses are tingling.</p></pre>solarnoise: <pre><p>I see your comment got upvoted and my reply and OP got downvoted. Real nice community you got here, friends. I&#39;ll be sure the door doesn&#39;t hit me on the way out.</p></pre>icholy: <pre><p>I think it&#39;s just being upvoted because it&#39;s funny. Don&#39;t know why you got downvoted.</p></pre>solarnoise: <pre><p>Sorry it came across that way.</p> <p>I&#39;m the creator of a plugin for a notable art program, and I wrote a binary part in golang to help parse files. I needed concurrency and just don&#39;t have the chops or patience for C++.</p> <p>One thing I need to check for (as it can absolutely mess things up) is whether the user has the debug flag enabled for the host program. In Windows it&#39;s a registry key and in Mac it&#39;s in defaults. I just need to retrieve it.</p> <p>I&#39;m not sure what else to say... I have a long reddit post history and you can derive my real identity from it easily enough. I work in the video games industry but the plugin is my side project.</p> <p>As an aside, wouldn&#39;t registry fiddling be one of the most obvious things an AV would catch?</p></pre>4ad: <pre><p>You can call <a href="https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/defaults.1.html" rel="nofollow">defaults(1)</a> through <code>os.Exec</code>.</p></pre>GoTheFuckToBed: <pre><p>settings are stored in plists files <a href="https://github.com/DHowett/go-plist" rel="nofollow">https://github.com/DHowett/go-plist</a></p></pre>ChristophBerger: <pre><p>The only match I found on Github is <a href="https://github.com/grapswiz/dfs" rel="nofollow">grapswiz/dfs</a> (Search: <code>language:go sort:stars mac defaults</code>). Under the hood, it simply seems to call the <code>defaults</code> command (see the &#34;commands&#34; field in <a href="https://github.com/grapswiz/dfs/blob/master/definitions/10.12/dock.json" rel="nofollow">dock.json</a>. </p> <p>Maybe that&#39;s what your code could do, too - call <code>defaults</code> via <code>os.Exec()</code> and fetch the output.</p></pre>solarnoise: <pre><p>Great, thank you! That sounds like it&#39;ll work.</p></pre>gogroob: <pre><p>You need to use CGO to interface with CFPreferences. I have an example here <a href="https://github.com/groob/mackit/blob/master/example/main.go" rel="nofollow">https://github.com/groob/mackit/blob/master/example/main.go</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

400 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传