{"id":33909,"date":"2021-10-14T17:03:49","date_gmt":"2021-10-14T21:03:49","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=33909"},"modified":"2021-10-15T15:58:18","modified_gmt":"2021-10-15T19:58:18","slug":"xpc-services-methods-not-necessarily-run-on-main-thread","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/10\/14\/xpc-services-methods-not-necessarily-run-on-main-thread\/","title":{"rendered":"XPC Service&rsquo;s Methods Not Necessarily Run on Main Thread"},"content":{"rendered":"<p><a href=\"https:\/\/blog.eternalstorms.at\/2021\/10\/14\/developer-tip-an-xpc-services-methods-arent-necessarily-run-on-the-main-thread\/\">Matthias Gansrigler<\/a>:<\/p>\n<blockquote cite=\"https:\/\/blog.eternalstorms.at\/2021\/10\/14\/developer-tip-an-xpc-services-methods-arent-necessarily-run-on-the-main-thread\/\">\n<p>After subsequently moving them into an XPC service and thinking it would &ldquo;just work&rdquo;, I found that it didn&rsquo;t. At least not reliably. Maybe every 8th or 9th time, yes, it did all it was asked to do, but every other time, it outright refused to execute Apple Scripts.<\/p>\n<p>After two days of desperate attempts to get it working correctly, and almost giving up on the XPC privilege separation entirely for this, I figured I&rsquo;d check to see if the Apple Scripts were being executed on the main thread.<\/p>\n<\/blockquote>\n\n<p id=\"xpc-services-methods-not-necessarily-run-on-main-thread-update-2021-10-15\">Update (2021-10-15): <a href=\"https:\/\/twitter.com\/tclementdev\/status\/1448771845424140291\">Thomas Clement<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/tclementdev\/status\/1448771845424140291\">\n<p>It is documented that <code>NSXPCConnection<\/code> calls back on the connection&rsquo;s internal private queue.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/iTod\/status\/1449100193002045448\">Todd Ditchendorf<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/iTod\/status\/1449100193002045448\">\n<p>I was tinkering with creating an app with an XPC service around 2013 and gave up cos it was flakey. In hindsight, I&rsquo;m pretty sure this was the problem.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Matthias Gansrigler: After subsequently moving them into an XPC service and thinking it would &ldquo;just work&rdquo;, I found that it didn&rsquo;t. At least not reliably. Maybe every 8th or 9th time, yes, it did all it was asked to do, but every other time, it outright refused to execute Apple Scripts. After two days of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-10-14T21:03:53Z","apple_news_api_id":"4d42715c-8f32-4954-a234-9307ed6663e6","apple_news_api_modified_at":"2021-10-15T19:58:21Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/ATUJxXI8ySVSiNJMH7WZj5g","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[159,30,2077,71,1473],"class_list":["post-33909","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-applescript","tag-mac","tag-macos-12","tag-programming","tag-xpc"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=33909"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33909\/revisions"}],"predecessor-version":[{"id":33927,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33909\/revisions\/33927"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=33909"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=33909"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=33909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}