{"id":55,"date":"2019-12-18T18:30:09","date_gmt":"2019-12-18T16:30:09","guid":{"rendered":"http:\/\/www.juustila.com\/antti\/?p=55"},"modified":"2020-02-06T10:08:51","modified_gmt":"2020-02-06T08:08:51","slug":"xcode-quick-action-scripts-to-jump-to-github-or-bitbucket-repository","status":"publish","type":"post","link":"https:\/\/www.juustila.com\/antti\/2019\/12\/18\/xcode-quick-action-scripts-to-jump-to-github-or-bitbucket-repository\/","title":{"rendered":"Xcode quick action scripts to jump to GitHub or Bitbucket repository"},"content":{"rendered":"\n<p>Stumbled upon this handy little macOS&nbsp;<a href=\"https:\/\/github.com\/wojteklu\/xcode-open-on-github\">quick action script project in GitHub<\/a>&nbsp;which support opening the code selected in <a href=\"https:\/\/developer.apple.com\/xcode\/\">Xcode<\/a> in a browser so that the selected code file in GitHub repository is opened and selected lines are highlighted in the browser. Or you could copy the link from Xcode to GitHub hosted project, while from Xcode, and share the link to someone by email or whatever.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"702\" src=\"http:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github-1024x702.png\" alt=\"\" class=\"wp-image-60\" srcset=\"https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github-1024x702.png 1024w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github-300x206.png 300w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github-768x526.png 768w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github-1536x1053.png 1536w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github-1568x1075.png 1568w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/open_on_github.png 1742w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption><em>Image from the original repo<\/em> by wojteklu<\/figcaption><\/figure>\n\n\n\n<p>Neat, wanted to try it out and cloned the project and installed the <a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/LanguagesUtilities\/Conceptual\/MacAutomationScriptingGuide\/index.html\">action scripts<\/a>. That was easy, just double click on the scripts and they are installed.<\/p>\n\n\n\n<p>I tried this with a project that is actually hosted in Bitbucket.org. Obviously it didn&#8217;t work out well. I forked the project, cloned it and copied and opened the action scripts in <a href=\"https:\/\/support.apple.com\/guide\/automator\/welcome\/mac\">Automator<\/a> app, edited the scripts to fit Bitbucket and now I have another pair of scripts which do work also with Bitbucket hosted repositories!<\/p>\n\n\n\n<p>The changes to the scripts were quite easy to implement. Just change .com to .org, and instead of GitHub&#8217;s &#8220;blob&#8221; path, use the Bitbucket&#8217;s &#8220;src&#8221; path for the code files. And instead of addressing code lines the GitHub way (#L54-L58), use the Bitbucket&#8217;s way (#lines-33:35). Here&#8217;s an example link to a GitHub repo&#8230;<\/p>\n\n\n\n<p><code>https:\/\/github.com\/anttijuu\/PluginDllDemo\/blob\/0f7b83f7ada5613cb0561a63a8c7d09f95f46144\/EasyCryptoReversePlugin\/EasyCryptoPlugin.cpp#L54-L58<\/code><\/p>\n\n\n\n<p>&#8230; and here&#8217;s an example of a Bitbucket link (<em>note: these links to BitBucket project ohar2014 are no longer valid since I have chopped the project into separate components in separate repositories<\/em>):<\/p>\n\n\n\n<p><code>https:\/\/bitbucket.org\/anttijuu\/ohar2014\/src\/e6fd26ef3d142d3da0cbe5969e6f037e465cede5\/BaseLayer\/ConfigurationDataItem.cpp#lines-33:35<\/code><\/p>\n\n\n\n<p>The long code in both of the links is the current commit id of the version I&#8217;m viewing in Xcode. And here&#8217;s the relevant parts of my new shiny Action script source code&#8230;<\/p>\n\n\n\n<!-- HTML generated using hilite.me --><div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\">on run {input<span style=\"color: #666666\">,<\/span> parameters}\n\ttell application <span style=\"color: #BA2121\">\"Xcode\"<\/span>\n\t\t<span style=\"color: #008000; font-weight: bold\">set<\/span> activeDocument to document <span style=\"color: #666666\">1<\/span> whose name ends <span style=\"color: #008000; font-weight: bold\">with<\/span> (word <span style=\"color: #666666\">-1<\/span> of (<span style=\"color: #008000; font-weight: bold\">get<\/span> name of window <span style=\"color: #666666\">1<\/span>))\n\t\t<span style=\"color: #008000; font-weight: bold\">set<\/span> activeDocumentPath to path of activeDocument\n\t\t<span style=\"color: #008000; font-weight: bold\">set<\/span> currentLines to selected paragraph range of activeDocument\n\t\t<span style=\"color: #008000; font-weight: bold\">set<\/span> startLine to <span style=\"color: #008000; font-weight: bold\">get<\/span> item <span style=\"color: #666666\">1<\/span> of currentLines\n\t\t<span style=\"color: #008000; font-weight: bold\">set<\/span> endLine to <span style=\"color: #008000; font-weight: bold\">get<\/span> item <span style=\"color: #666666\">2<\/span> of currentLines\n\tend tell\n\t\n\t<span style=\"color: #008000; font-weight: bold\">set<\/span> repositoryUrl to <span style=\"color: #008000; font-weight: bold\">do<\/span> shell script <span style=\"color: #BA2121\">\"cd $(dirname \"<\/span> <span style=\"color: #666666\">&amp;<\/span> activeDocumentPath <span style=\"color: #666666\">&amp;<\/span> <span style=\"color: #BA2121\">\"); git remote -v | grep fetch | awk '{print $2}' | sed 's\/git@\/https:\\\\\/\\\\\/\/' | sed 's\/org:\/org\\\\\/\/' | sed 's\/\\\\.git\/\/'\"<\/span>\n\t\n\t<span style=\"color: #008000; font-weight: bold\">set<\/span> pathToRepositoryDirLocation to <span style=\"color: #008000; font-weight: bold\">do<\/span> shell script <span style=\"color: #BA2121\">\"cd $(dirname \"<\/span> <span style=\"color: #666666\">&amp;<\/span> activeDocumentPath <span style=\"color: #666666\">&amp;<\/span> <span style=\"color: #BA2121\">\"); git rev-parse --show-toplevel \"<\/span>\n\t\n\t<span style=\"color: #008000; font-weight: bold\">set<\/span> activeFilePathInRepository to replace_text(activeDocumentPath<span style=\"color: #666666\">,<\/span> pathToRepositoryDirLocation<span style=\"color: #666666\">,<\/span> <span style=\"color: #BA2121\">\"\"<\/span>)\n\t\n\t<span style=\"color: #008000; font-weight: bold\">set<\/span> currentCommit to <span style=\"color: #008000; font-weight: bold\">do<\/span> shell script <span style=\"color: #BA2121\">\"cd $(dirname \"<\/span> <span style=\"color: #666666\">&amp;<\/span> activeDocumentPath <span style=\"color: #666666\">&amp;<\/span> <span style=\"color: #BA2121\">\"); git rev-parse HEAD\"<\/span>\n\t\n\t<span style=\"color: #008000; font-weight: bold\">set<\/span> bitbucketUrl to repositoryUrl <span style=\"color: #666666\">&amp;<\/span> <span style=\"color: #BA2121\">\"\/src\/\"<\/span> <span style=\"color: #666666\">&amp;<\/span> currentCommit <span style=\"color: #666666\">&amp;<\/span> activeFilePathInRepository <span style=\"color: #666666\">&amp;<\/span> <span style=\"color: #BA2121\">\"#lines-\"<\/span> <span style=\"color: #666666\">&amp;<\/span> startLine <span style=\"color: #666666\">&amp;<\/span> <span style=\"color: #BA2121\">\":\"<\/span> <span style=\"color: #666666\">&amp;<\/span> endLine\n\t\n\t<span style=\"color: #008000; font-weight: bold\">set<\/span> the clipboard to bitbucketUrl\n\t\n\t<span style=\"color: #008000; font-weight: bold\">return<\/span> input\nend run\n<\/pre><\/div>\n\n\n\n<p>&#8230;and the script itself installed and visible in the Xcode menu!<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"673\" src=\"http:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/N\u00e4ytt\u00f6kuva-2019-12-18-kello-17.49.17-1024x673.png\" alt=\"\" class=\"wp-image-63\" srcset=\"https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/N\u00e4ytt\u00f6kuva-2019-12-18-kello-17.49.17-1024x673.png 1024w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/N\u00e4ytt\u00f6kuva-2019-12-18-kello-17.49.17-300x197.png 300w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/N\u00e4ytt\u00f6kuva-2019-12-18-kello-17.49.17-768x505.png 768w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2019\/12\/N\u00e4ytt\u00f6kuva-2019-12-18-kello-17.49.17.png 1400w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption>Action scripts installed for Bitbucket.<\/figcaption><\/figure>\n\n\n\n<p>I also made a pull request to the original project, in case he wants to merge my contribution into it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stumbled upon this handy little macOS&nbsp;quick action script project in GitHub&nbsp;which support opening the code selected in Xcode in a browser so that the selected code file in GitHub repository is opened and selected lines are highlighted in the browser. Or you could copy the link from Xcode to GitHub hosted project, while from Xcode, &hellip; <a href=\"https:\/\/www.juustila.com\/antti\/2019\/12\/18\/xcode-quick-action-scripts-to-jump-to-github-or-bitbucket-repository\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Xcode quick action scripts to jump to GitHub or Bitbucket repository&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","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":[2],"tags":[18,21,19,20,22],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-coding","tag-action-script","tag-bitbucket","tag-git","tag-github","tag-xcode"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":8,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":121,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/55\/revisions\/121"}],"wp:attachment":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}