Help us understand the problem. What is going on with this article?

カフェでトイレに行ってるときに、Macが盗まれそうになるとGet Wildが流れるようにする

More than 3 years have passed since last update.

概要

①NoSleepアプリのcliのインストール

https://github.com/integralpro/nosleep/releases
こちらからインストール

②スクリプトを書く

  • osascriptでitunesから再生しようとしましたが、停止ボタンで止められたら困るので
    音楽ファイルを直接再生することにしました
#!/bin/sh

MUSIC_PATH="/tmp/GetWild.m4a"

checkNoSleepCtrl()
{
  if [ ! -f $(which NoSleepCtrl) ]; then
    echo "Please install NoSleepCtrl from "
    echo "  https://github.com/integralpro/nosleep/releases"
    echo " "
    echo "Install it with CLI included in it. It's necessary to prevent"
    echo "your macbook from going to sleep when somebody closes the clamshell."
    echo "When you launch this script it will automatically turn the 'NoSleep'"
    echo "mode ON and when you exit the script with Ctrl-C, the 'NoSleep' mode"
    echo "will automatically be turned OFF."
    echo "(You are not required to be running it in the tray)"
    echo " "
    exit
  fi
}

forceVolume()
{
  local volume=$(osascript -e "(get volume settings)'s output volume")
  local muted=$(osascript -e "(get volume settings)'s output muted")
  while :; do
    NoSleepCtrl -a -s 1
    NoSleepCtrl -b -s 1
    osascript -e "set volume 100"
    sleep 0.1
  done &
  local pid=$!
  trap "
    NoSleepCtrl -a -s 0
    NoSleepCtrl -b -s 0
    kill $pid
    osascript -e 'set volume output volume $volume'
    osascript -e 'set volume output muted $muted'
    exit
  " SIGINT
}

isClamshellOpen()
{
  [ $(
    ioreg -r -k AppleClamshellState -d 4 |
    grep AppleClamshellState |
    head -1 |
    cut -d = -f 2
  ) = Yes ]
}

getWildAndTough()
{  
  # Check NoSleepCtrl available
  checkNoSleepCtrl

  # Init local variables
  local intrusion_detected=false
  local counter=0

  # Launch volume forcer
  forceVolume

  # Execution loop
  while :; do
    if $intrusion_detected || $(isClamshellOpen); then
      let counter=5
      say -v Otoya "爆破スイッチが起動されました"
      say -v Otoya "5秒後に爆発します"
      while [ $counter -gt 0 ]; do
        say -v Otoya $counter
        let counter-=1
        sleep 1
      done
      afplay $MUSIC_PATH
      intrusion_detected=true
    fi
    sleep 1
  done
}

getWildAndTough

③あとは起動してトイレに行くだけです

  • Let's try!

追記

  • @mpyw さんより、下記改善頂きました!
  • 元の音量とミュート状態をリストアするように改善
  • 実行中に音量やミュート状態を操作されても爆音を強制するように強化
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした