{"id":1450,"date":"2009-05-06T17:43:49","date_gmt":"2009-05-06T20:43:49","guid":{"rendered":"http:\/\/brockerhoff.net\/bb\/viewtopic.php?p=2696"},"modified":"2010-05-08T10:59:23","modified_gmt":"2010-05-08T13:59:23","slug":"re-cocoa-musings-pt-6-2","status":"publish","type":"post","link":"https:\/\/brockerhoff.net\/blog\/2009\/05\/06\/re-cocoa-musings-pt-6-2\/","title":{"rendered":"Re: Cocoa musings pt.6"},"content":{"rendered":"<p><a href=\"http:\/\/0xced.blogspot.com\/\">C\u00e9dric Luthi<\/a> has posted <a href=\"http:\/\/0xced.blogspot.com\/2008\/02\/upgrading-system-preference-pane.html\">another take<\/a> on the mechanics of reopening a System Preferences pane (or is it panel?). Worth a read; however, I would propose a shorter piece of code for his <a href=\"http:\/\/snipplr.com\/view\/3924\/reload-a-preference-pane\/\">relaunch snippet<\/a>, combining two of my recent posts:<\/p>\n<pre><code>int main(int argc, char **argv) { \r\n\u00a0 \u00a0char dummy; \r\n\u00a0 \u00a0read(STDIN_FILENO, &amp;dummy, 1); \r\n\u00a0 \u00a0CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (UInt8*)argv[1], strlen(argv[1]), FALSE); \r\n\u00a0 \u00a0CFArrayRef aurl = CFArrayCreate(kCFAllocatorDefault, (const void**)&amp;url, 1, NULL);\r\n\u00a0 \u00a0FSRef ref;\r\n\u00a0 \u00a0if (LSFindApplicationForInfo(0, CFSTR(\"com.apple.systempreferences\"), NULL, &amp;ref, NULL)==noErr) {\r\n\u00a0 \u00a0\u00a0 \u00a0LSApplicationParameters parms = {0,kLSLaunchDefaults,&amp;ref,NULL,NULL,NULL,NULL};\r\n\u00a0 \u00a0\u00a0 \u00a0LSOpenURLsWithRole(aurl, kLSRolesAll, NULL, &amp;parms, NULL, 0);\r\n\u00a0 \u00a0\u00a0 \u00a0}\r\n\u00a0 \u00a0}\r\n}<\/code><\/pre>\n<p>and the code to launch this tool (from within the preference panel itself) is:<\/p>\n<pre><code>\u00a0 \u00a0NSTask* task = [[NSTask alloc] init]; \r\n\u00a0 \u00a0[task setLaunchPath:@\"\/path\/to\/tool\"]; \r\n\u00a0 \u00a0[task setArguments:[NSArray arrayWithObject:[[NSBundle bundleForClass:[self class]] bundlePath]]]; \r\n\u00a0 \u00a0[task setStandardInput:[NSPipe pipe]]; \r\n\u00a0 \u00a0[task launch]; \r\n\u00a0 \u00a0[NSApp terminate:nil];<\/code><\/pre>\n<p>No need to pass the calling program&#8217;s process identifier, and it works from Tiger (10.4) on up.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C\u00e9dric Luthi has posted another take on the mechanics of reopening a System Preferences pane (or is it panel?). Worth a read; however, I would propose a shorter piece of code for his relaunch snippet, combining two of my recent posts: int main(int argc, char **argv) { \u00a0 \u00a0char dummy; \u00a0 \u00a0read(STDIN_FILENO, &amp;dummy, 1); \u00a0 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,19],"tags":[26],"class_list":["post-1450","post","type-post","status-publish","format-standard","hentry","category-dev","category-software","tag-cocoa"],"featured_image_src":null,"author_info":{"display_name":"Rainer Brockerhoff","author_link":"https:\/\/brockerhoff.net\/blog\/author\/rbrockerhoff\/"},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1q3Zc-no","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/posts\/1450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/comments?post=1450"}],"version-history":[{"count":0,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/posts\/1450\/revisions"}],"wp:attachment":[{"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/media?parent=1450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/categories?post=1450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brockerhoff.net\/blog\/wp-json\/wp\/v2\/tags?post=1450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}