Skip to content

Instantly share code, notes, and snippets.

@senki
Last active July 25, 2016 03:09
Show Gist options
  • Select an option

  • Save senki/a37172794bdedd3f479b to your computer and use it in GitHub Desktop.

Select an option

Save senki/a37172794bdedd3f479b to your computer and use it in GitHub Desktop.

Revisions

  1. senki revised this gist Jul 25, 2016. 3 changed files with 4 additions and 7 deletions.
    6 changes: 3 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@
    Make sure the terminal notifier is installed. Install it wia `brew install terminal-notifier` command.
    The script assumes the **iTerm** is installed. Go get it, or edit the `npm-update-notifier.sh` for your need.

    1. Put `npm-update-notifier.sh` to your `~/bin/` directory
    2. Put `npm.npm.update-notifier.plist` to your `~/Library/LaunchAgents/` directory
    3. Run `launchctl load ~/Library/LaunchAgents/npm.npm.update-notifier.plist`
    1. Put `notify-update-npm.sh` to your `~/bin/` directory
    2. Put `notify.update.npm.plist` to your `~/Library/LaunchAgents/` directory
    3. Run `launchctl load ~/Library/LaunchAgents/notify.update.npm.plist`

    This script is run twice a day at 11 AM & 4 PM.
    Based on Based on Chris Streeters' `brew-update-notifier.sh` work from https://gist.github.com/streeter/3254906
    3 changes: 0 additions & 3 deletions notify-update-npm.sh
    Original file line number Diff line number Diff line change
    @@ -8,9 +8,6 @@
    # brew install terminal-notifier
    #

    export PATH="/usr/local/sbin:/usr/local/bin:$PATH"


    NPM_EXEC='/usr/local/bin/npm'
    TERMINAL_NOTIFIER='/usr/local/bin/terminal-notifier'
    NOTIF_ARGS="-activate com.googlecode.iterm2 -sound NotificationCenter"
    2 changes: 1 addition & 1 deletion notify.update.npm.plist
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    <key>ProgramArguments</key>
    <array>
    <string>/bin/bash</string>
    <string>/Users/maulis/bin/notify-update-npm</string>
    <string>/Users/USERNAME/bin/notify-update-npm.sh</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
  2. senki revised this gist Jul 25, 2016. 2 changed files with 20 additions and 18 deletions.
    17 changes: 10 additions & 7 deletions npm-update-notifier.sh → notify-update-npm.sh
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,17 @@
    # Notify of npm updates via Notification Center on Mac OS X
    #
    # Author Csaba Maulis @_senki
    # Based on Chris Streeters' `brew-update-notifier.sh` (http://www.chrisstreeter.com)
    # Based on Chris Streeters (http://www.chrisstreeter.com) `brew-update-notifier.sh`
    # Requires: terminal-notifier. Install with:
    # brew install terminal-notifier
    #

    export PATH="/usr/local/sbin:/usr/local/bin:$PATH"


    TERM_APP='/Applications/iTerm.app'
    NPM_EXEC='/usr/local/bin/npm'
    TERMINAL_NOTIFIER='/usr/local/bin/terminal-notifier'
    NOTIF_ARGS="-sender com.googlecode.iterm2 -activate com.googlecode.iterm2 -sound NotificationCenter"
    NOTIF_ARGS="-activate com.googlecode.iterm2 -sound NotificationCenter"

    # Remove pinned package from the list of outdated package
    outdated=`$NPM_EXEC outdated -g | awk '{if (NR!=1) {print $1}}'`
    @@ -19,8 +22,8 @@ if [ -z "$outdated" ] ; then
    if [ -e $TERMINAL_NOTIFIER ]; then
    # No updates available
    $TERMINAL_NOTIFIER $NOTIF_ARGS \
    -title "No npm Updates Available" \
    -message "No updates available yet for any global npm(1) packages."
    -title "NPM: No Updates Available" \
    -message "No updates available yet for any global package."
    fi
    else
    # We've got an outdated package or two
    @@ -29,9 +32,9 @@ else
    if [ -e $TERMINAL_NOTIFIER ]; then
    lc=$((`echo "$outdated" | wc -l`))
    if [ $lc -gt 1 ]; then
    title="npm Updates Available"
    title="NPM: $lc Updates Available"
    else
    title="An npm Update Available"
    title="NPM: 1 Updates Available"
    fi
    outdated=`echo "$outdated" | tail -$lc`
    message=`echo "$outdated" | head -5`
    21 changes: 10 additions & 11 deletions npm.npm.update-notifier.plist → notify.update.npm.plist
    Original file line number Diff line number Diff line change
    @@ -5,29 +5,28 @@
    <key>EnableGlobbing</key>
    <false/>
    <key>Label</key>
    <string>npm.npm.update-notifier</string>
    <string>notify.update.npm</string>
    <key>ProgramArguments</key>
    <array>
    <string>/bin/bash</string>
    <string>~/bin/npm-update-notifier.sh</string>
    <string>/Users/maulis/bin/notify-update-npm</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
    <key>PATH</key>
    <string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>
    <key>StartInterval</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/npm.npm.update-notifier.err</string>
    <string>/tmp/notify.update.npm.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/npm.npm.update-notifier.out</string>
    <string>/tmp/notify.update.npm.out</string>
    <key>StartCalendarInterval</key>
    <array>
    <dict>
    <key>Hour</key>
    <integer>11</integer>
    <key>Minute</key>
    <integer>0</integer>
    </dict>
    <dict>
    <key>Hour</key>
    <integer>16</integer>
    <integer>15</integer>
    <key>Minute</key>
    <integer>0</integer>
    </dict>
  3. senki revised this gist Jun 9, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,4 @@ The script assumes the **iTerm** is installed. Go get it, or edit the `npm-updat
    3. Run `launchctl load ~/Library/LaunchAgents/npm.npm.update-notifier.plist`

    This script is run twice a day at 11 AM & 4 PM.
    Based on Based on Chris Streeters' `brew-update-notifier.sh` work from http://www.chrisstreeter.com
    Based on Based on Chris Streeters' `brew-update-notifier.sh` work from https://gist.github.com/streeter/3254906
  4. senki created this gist Jun 9, 2015.
    11 changes: 11 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # Notify of global npm updates via Notification Center on Mac OS X

    Make sure the terminal notifier is installed. Install it wia `brew install terminal-notifier` command.
    The script assumes the **iTerm** is installed. Go get it, or edit the `npm-update-notifier.sh` for your need.

    1. Put `npm-update-notifier.sh` to your `~/bin/` directory
    2. Put `npm.npm.update-notifier.plist` to your `~/Library/LaunchAgents/` directory
    3. Run `launchctl load ~/Library/LaunchAgents/npm.npm.update-notifier.plist`

    This script is run twice a day at 11 AM & 4 PM.
    Based on Based on Chris Streeters' `brew-update-notifier.sh` work from http://www.chrisstreeter.com
    49 changes: 49 additions & 0 deletions npm-update-notifier.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/bin/bash
    #
    # Notify of npm updates via Notification Center on Mac OS X
    #
    # Author Csaba Maulis @_senki
    # Based on Chris Streeters' `brew-update-notifier.sh` (http://www.chrisstreeter.com)
    # Requires: terminal-notifier. Install with:
    # brew install terminal-notifier

    TERM_APP='/Applications/iTerm.app'
    NPM_EXEC='/usr/local/bin/npm'
    TERMINAL_NOTIFIER='/usr/local/bin/terminal-notifier'
    NOTIF_ARGS="-sender com.googlecode.iterm2 -activate com.googlecode.iterm2 -sound NotificationCenter"

    # Remove pinned package from the list of outdated package
    outdated=`$NPM_EXEC outdated -g | awk '{if (NR!=1) {print $1}}'`

    if [ -z "$outdated" ] ; then
    if [ -e $TERMINAL_NOTIFIER ]; then
    # No updates available
    $TERMINAL_NOTIFIER $NOTIF_ARGS \
    -title "No npm Updates Available" \
    -message "No updates available yet for any global npm(1) packages."
    fi
    else
    # We've got an outdated package or two

    # Nofity via Notification Center
    if [ -e $TERMINAL_NOTIFIER ]; then
    lc=$((`echo "$outdated" | wc -l`))
    if [ $lc -gt 1 ]; then
    title="npm Updates Available"
    else
    title="An npm Update Available"
    fi
    outdated=`echo "$outdated" | tail -$lc`
    message=`echo "$outdated" | head -5`
    if [ "$outdated" != "$message" ]; then
    message="Some of the globally outdated package are:
    $message"
    else
    message="The following globally package are outdated:
    $message"
    fi
    # Send to the Nofication Center
    $TERMINAL_NOTIFIER $NOTIF_ARGS \
    -title "$title" -message "$message"
    fi
    fi
    36 changes: 36 additions & 0 deletions npm.npm.update-notifier.plist
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>EnableGlobbing</key>
    <false/>
    <key>Label</key>
    <string>npm.npm.update-notifier</string>
    <key>ProgramArguments</key>
    <array>
    <string>/bin/bash</string>
    <string>~/bin/npm-update-notifier.sh</string>
    </array>
    <key>StartInterval</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/npm.npm.update-notifier.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/npm.npm.update-notifier.out</string>
    <key>StartCalendarInterval</key>
    <array>
    <dict>
    <key>Hour</key>
    <integer>11</integer>
    <key>Minute</key>
    <integer>0</integer>
    </dict>
    <dict>
    <key>Hour</key>
    <integer>16</integer>
    <key>Minute</key>
    <integer>0</integer>
    </dict>
    </array>
    </dict>
    </plist>