<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: darrenberg</title>
    <description>The latest articles on DEV Community by darrenberg (@darrenberg).</description>
    <link>https://dev.to/darrenberg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F162038%2F8b26839d-09d9-4d75-907e-43bc51a3d5e4.jpeg</url>
      <title>DEV Community: darrenberg</title>
      <link>https://dev.to/darrenberg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darrenberg"/>
    <language>en</language>
    <item>
      <title>Customized GitHub Notifications for MacOS</title>
      <dc:creator>darrenberg</dc:creator>
      <pubDate>Mon, 02 Dec 2019 10:18:22 +0000</pubDate>
      <link>https://dev.to/doctolib/customized-github-notifications-for-macos-18d4</link>
      <guid>https://dev.to/doctolib/customized-github-notifications-for-macos-18d4</guid>
      <description>&lt;p&gt;GitHub has two choices for notifications: email or a small blue dot in the corner of the page. As a developer at Doctolib I get lots of notifications throughout the day, which means either frequent email alerts or keeping a close eye on the blue dot.&lt;/p&gt;

&lt;p&gt;I wanted something in the middle, so I wrote a script to generate desktop notifications at a frequency I can choose.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zcF3ilvr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/88wked9yl00thn5z0wqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zcF3ilvr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/88wked9yl00thn5z0wqn.png" alt="Alt Text" width="758" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the repository if you want to skip ahead to the code: &lt;a href="https://github.com/darrenberg/github-notifications"&gt;https://github.com/darrenberg/github-notifications&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Notification Content
&lt;/h1&gt;

&lt;p&gt;The GitHub API has everything we need and we can parse the output with a command-line utility called jq.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fA4DVbdu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/425aa2sedvybjlt9gbb0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fA4DVbdu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/425aa2sedvybjlt9gbb0.png" alt="Alt Text" width="800" height="36"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CcDwZWy1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/ppwwy4g0baxsqx2pz9o0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CcDwZWy1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/ppwwy4g0baxsqx2pz9o0.png" alt="Alt Text" width="800" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Authentication and Password Storage
&lt;/h1&gt;

&lt;p&gt;The easiest way to connect to the GitHub API is by creating a personal access token, which can be scoped to only access notifications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pQdbISDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/53n7n7oyqimkdkizbrl7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pQdbISDF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/53n7n7oyqimkdkizbrl7.png" alt="Alt Text" width="748" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, storing this token in my script wouldn’t be very secure, so I used the MacOS Keychain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YuiAAAQN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/oqc97vt62s5ko008l92k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YuiAAAQN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/oqc97vt62s5ko008l92k.png" alt="Remember to generate a new personal access token if you accidentally post it on DEV" width="800" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s easy to add an entry from Keychain Access and you can retrieve it from the command line with find-generic-password. For more information, check out &lt;a href="https://www.netmeister.org/blog/keychain-passwords.html"&gt;https://www.netmeister.org/blog/keychain-passwords.html&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Desktop Notifications
&lt;/h1&gt;

&lt;p&gt;I used terminal-notifier to create the desktop notification. You can control whether it’s a banner or alert in the MacOS Notification Preferences.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Piped Message Data!"&lt;/span&gt; | terminal-notifier &lt;span class="nt"&gt;-sound&lt;/span&gt; default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hR1AbOAP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/41vcis03qkxhu6xg6erg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hR1AbOAP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/41vcis03qkxhu6xg6erg.png" alt="Alt Text" width="716" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The Script!
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

USER=$(git config user.email)
TOKEN=$(security find-generic-password -a github_token -w)

while true
do 
  curl -s -u $USER:$TOKEN  https://api.github.com/notifications \
    | jq -r '.[] | select(.unread) | [.subject.type, .reason, .subject.title] | @sh \
    | xargs -n 3 sh -c \
    'terminal-notifier -title "GitHub Notification" -subtitle "$0 $1" -message "$2" -open “https://github.com/notifications"'
  sleep $(($1 * 60))
done

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simply pass the number of minutes to wait between calls (e.g. ./notify.sh 10 will run every 10 minutes) and it will show you all your unread notifications with a link to GitHub. Or take out the infinite loop and run it as a cron job.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8grU_KxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/gk5xb3vdf3n20259xsu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8grU_KxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://thepracticaldev.s3.amazonaws.com/i/gk5xb3vdf3n20259xsu0.png" alt="Alt Text" width="586" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Detailed installation instructions can be found at &lt;a href="https://github.com/darrenberg/github-notifications"&gt;https://github.com/darrenberg/github-notifications&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;According to Larry Wall, the original author of the Perl programming language, there are three great virtues of a programmer; Laziness, Impatience and Hubris:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Come be lazy at Doctolib!&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://about.doctolib.com/careers/engineering.html"&gt;https://about.doctolib.com/careers/engineering.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>hottips</category>
      <category>github</category>
      <category>macos</category>
      <category>jq</category>
    </item>
  </channel>
</rss>
