Skip to content

Instantly share code, notes, and snippets.

@ddqp
Forked from ralph089/.wakeup
Created October 31, 2016 08:35
Show Gist options
  • Save ddqp/0c762b80a7cf442d70a500ecb94e8ff8 to your computer and use it in GitHub Desktop.
Save ddqp/0c762b80a7cf442d70a500ecb94e8ff8 to your computer and use it in GitHub Desktop.

Revisions

  1. Ralph revised this gist Aug 8, 2016. No changes.
  2. Ralph revised this gist Aug 8, 2016. No changes.
  3. Ralph revised this gist Aug 8, 2016. No changes.
  4. Ralph revised this gist Jul 31, 2016. 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
    @@ -1,4 +1,4 @@
    There is a program called [SleepWatcher] (http://www.bernhard-baehr.de/) that monitors sleep, wakeup and idleness of a Mac. To restart Bluetooth everytime the machine comes up from sleep, SleepWatcher executes the script from above automatically. Restarting Bluetooth takes approximately 2s, so it doesn't attract negative attention.
    There is a program called [SleepWatcher] (http://www.bernhard-baehr.de/) that monitors sleep, wakeup and idleness of a Mac. To restart Bluetooth everytime your Mac comes up from sleep, you have to tell SleepWatcher to execute the script from above automatically. Restarting Bluetooth takes approximately 2s, so it doesn't attract negative attention.

    The script makes use of BlueUtil, so you have to install it too. (I'm assuming you have HomeBrew installed)

  5. Ralph revised this gist Jul 31, 2016. 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
    @@ -1,4 +1,4 @@
    There is a program called [SleepWatcher] (http://www.bernhard-baehr.de/) that monitors sleep, wakeup and idleness of a Mac. Everytime the Machine comes up from sleep, you can use the script to restart Bluetooth within a bashscript automatically (restart takes approximately 2s, so it doesn't attract negative attention).
    There is a program called [SleepWatcher] (http://www.bernhard-baehr.de/) that monitors sleep, wakeup and idleness of a Mac. To restart Bluetooth everytime the machine comes up from sleep, SleepWatcher executes the script from above automatically. Restarting Bluetooth takes approximately 2s, so it doesn't attract negative attention.

    The script makes use of BlueUtil, so you have to install it too. (I'm assuming you have HomeBrew installed)

  6. Ralph revised this gist Jul 31, 2016. 1 changed file with 45 additions and 0 deletions.
    45 changes: 45 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    There is a program called [SleepWatcher] (http://www.bernhard-baehr.de/) that monitors sleep, wakeup and idleness of a Mac. Everytime the Machine comes up from sleep, you can use the script to restart Bluetooth within a bashscript automatically (restart takes approximately 2s, so it doesn't attract negative attention).

    The script makes use of BlueUtil, so you have to install it too. (I'm assuming you have HomeBrew installed)

    ```bash
    brew install sleepwatcher
    brew install blueutil
    ```

    To make use of SleepWatcher, you have to put the gist to ~/.wakeup (For more information about sleepwatcher open terminal and insert: man sleepwatcher)

    After you put your script to ~/.wakeup do the following:

    ```bash
    chmod +x ~/.wakeup
    ```

    Now you can test the script. Add the following command to your terminal:
    ```bash
    /usr/local/sbin/sleepwatcher --verbose -w ~/.wakeup
    ```

    Now you have to enter sleep mode and wakeup your Mac again. After that, you should see the following console output:

    ```
    Bluetooth on, restarting ...
    Bluetooth Module stopped
    Bluetooth Module started
    Successfully restarted Bluetooth
    sleepwatcher: wakeup: /Users/ralph/.wakeup: 0
    ```

    If it works, you can set up the user LaunchAgent by simlinking the example config files (more explanation can be found here: from https://www.kodiakskorner.com/log/258):

    ```bash
    ln -sfv /usr/local/Cellar/sleepwatcher/2.2/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist ~/Library/LaunchAgents/
    ```

    Then we tell launchd to load the configuration:
    ```bash
    launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher-20compatibility-localuser.plist
    ```

    For debugging purposes, you can enter Console App and search for "bt_restarter". Maybe there are some messages, indicating a problem.

  7. Ralph revised this gist Jul 31, 2016. No changes.
  8. Ralph revised this gist Jul 15, 2016. No changes.
  9. Ralph revised this gist May 3, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions .wakeup
    Original file line number Diff line number Diff line change
    @@ -8,12 +8,12 @@ BT="/usr/local/bin/blueutil"

    log() {
    echo "$@"
    logger -p user.notice -t bt_restarter "$@"
    logger -p notice -t bt_restarter "$@"
    }

    err() {
    echo "$@" >&2
    logger -p user.error -t bt_restarter "$@"
    logger -p error -t bt_restarter "$@"
    }

    if [ -f "$BT" ]; then
  10. Ralph revised this gist May 2, 2016. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions .wakeup
    Original file line number Diff line number Diff line change
    @@ -7,25 +7,25 @@
    BT="/usr/local/bin/blueutil"

    log() {
    echo "$@"
    logger -p user.notice -t bt_restarter "$@"
    echo "$@"
    logger -p user.notice -t bt_restarter "$@"
    }

    err() {
    echo "$@" >&2
    logger -p user.error -t bt_restarter "$@"
    echo "$@" >&2
    logger -p user.error -t bt_restarter "$@"
    }

    if [ -f "$BT" ]; then
    if [[ $("$BT" power) == *1 ]];
    then
    echo "Bluetooth on, restarting ..."
    $("$BT" power 0) &> /dev/null && echo "Bluetooth Module stopped" || (err "Couldn't stop Bluetooth Module" && exit 1)
    $("$BT" power 1) &> /dev/null && echo "Bluetooth Module started" || (err "Couldn't start Bluetooth Module" && exit 1)
    log "Successfully restarted Bluetooth" && exit 0
    else
    echo "Bluetooth is off, nothing to do ..."
    fi
    if [[ $("$BT" power) == *1 ]];
    then
    echo "Bluetooth on, restarting ..."
    ($("$BT" power 0) &> /dev/null && echo "Bluetooth Module stopped") || (err "Couldn't stop Bluetooth Module" && exit 1)
    ($("$BT" power 1) &> /dev/null && echo "Bluetooth Module started") || (err "Couldn't start Bluetooth Module" && exit 1)
    log "Successfully restarted Bluetooth" && exit 0
    else
    echo "Bluetooth is off, nothing to do ..."
    fi
    else
    err "Couldn't find blueutil, please install http://brewformulas.org/blueutil" && exit 1
    fi
    fi
  11. Ralph created this gist May 2, 2016.
    31 changes: 31 additions & 0 deletions .wakeup
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/bin/bash
    #
    # Restart Bluetooth Module on Mac OS X
    #
    # Requires Blueutil to be installed: http://brewformulas.org/blueutil

    BT="/usr/local/bin/blueutil"

    log() {
    echo "$@"
    logger -p user.notice -t bt_restarter "$@"
    }

    err() {
    echo "$@" >&2
    logger -p user.error -t bt_restarter "$@"
    }

    if [ -f "$BT" ]; then
    if [[ $("$BT" power) == *1 ]];
    then
    echo "Bluetooth on, restarting ..."
    $("$BT" power 0) &> /dev/null && echo "Bluetooth Module stopped" || (err "Couldn't stop Bluetooth Module" && exit 1)
    $("$BT" power 1) &> /dev/null && echo "Bluetooth Module started" || (err "Couldn't start Bluetooth Module" && exit 1)
    log "Successfully restarted Bluetooth" && exit 0
    else
    echo "Bluetooth is off, nothing to do ..."
    fi
    else
    err "Couldn't find blueutil, please install http://brewformulas.org/blueutil" && exit 1
    fi