äºç´æ¥æã«ãªã£ããã¡ããã¨ç®è¦ããtimerã³ãã³ãã欲ãã
前回ãradikoããããâ ããããé²é³ããrec_radikoru.appãä½ã£ããã©ãã«ãé²é³ãããã¨ã¯ã§ããããã«ãªã£ãã®ã ãã©...ãããããã®ä»ã®ãããã©ã¸ãªãé²é³ãããã¨ããiTunesãç®è¦ã¾ã代ããã«èµ·åãããã¨ãããã®ä»ãããããªæ¬²æ±ã湧ãã¦ããæã«ãç¾ç¶ã®rec_radikoru.appã§ã¯ã©ãã«ããªããªã...ã
ã¨ããã§ãOSXã«ãæé管çã®ä»çµã¿ã¯ç¨æããã¦ãããã·ã¹ãã ç°å¢è¨å® >> çã¨ãã«ã®ã¼ã§ãç¹°ãè¿ãã®ã¹ã±ã¸ã¥ã¼ã«ãè¨å®ã§ãããã§ãè¨å®ã§ãããã¨ã¯ãèµ·åã»ã¹ãªã¼ã解é¤ããçµäºã»ã¹ãªã¼ãã ããèµ·åããããã¹ãªã¼ã解é¤ããã¨ãããã¨ã¯ããã®æç¹ã§å®è¡ããããã¨ãããã¯ããªãã ãã©ãä½ãå®è¡ãããã¾ã§ã¯æå®ã§ããªãã®ã ãè¨å®ã§ããç¹°ãè¿ãã¹ã±ã¸ã¥ã¼ã«ãèµ·åç³»ã¨çµäºç³»ã§ãããã1ã¤ã ãã
ä½ãå®è¡ãããã®äºç´ã¯ãlaunchdãcronãããã«ã«ã¬ã³ãã¼ã¤ãã³ããªã©ã使ãã°è¨å®ã§ããããã ããããããã¡ããã¨æ©è½ããããã«ã¯macãè¦éãã¦ããªããã°ãªããªããã¹ãªã¼ãä¸ã ã¨ãäºç´ããæéã«ãªã£ã¦ãä½ããã¦ãããªãã®ã ...ããããåé¿ããããã«ã¯ãã¹ãªã¼ãããªãè¨å®ã§éç¨ãã¦ãã¾ããã¨ããæããããï¼ä½ã®è¦å´ããªãããã¹ã¦ã解決ãã¦ãã¾ãï¼
ã§ãããã£ããåãã£ã¦ããé«åº¦ãªã¹ãªã¼ãé¢é£ã®æ©è½ãç¡è¦ãã¦ãã¾ããã¨ã¯ããã¾ã好ã¾ãªããä½ã®ããã«ãWake On DemandãPower Napã¯ããã®ãããã¯ãã使ã£ã¦ããªãæã¯æ£ããã¹ãªã¼ããã¦æ¶è²»é»åãæå°ã«æ¼ãããå¿ è¦ã«å¿ãã¦ã¹ãªã¼ãã解é¤ãã¦ãå¿ è¦ãªå¦çãè¡ãã¨ãã姿å¢ããã¹ãã§ããã
ããããã¹ãªã¼ã解é¤ã¨é£æºããã¿ã¤ãã¼é§åã®ä»çµã¿ã¯ãOSXç°å¢ã«ã¯ç¨æããã¦ããªã*1ãï¼ã¨æã£ã¦ããï¼èªåã§pmsetã使ã£ã¦ãè¨å®ããã¿ã¤ãã¼ã¨é£æºããããã«äºåã«è¨å®ãã¦ããå¿ è¦ããããããã§ã¯é常ã«é¢åã§ãããé«åº¦ãªã¤ã³ã¿ã¼ãã§ã¼ã¹ãåããOSãªã®ã«ãã¿ã¤ãã¼æ©è½ã«ã¤ãã¦ã¯æ³£ãã¦ããããããç²æ«ã§ããã
rec_radikoru.appã§å®ç¾ããã¹ãªã¼ã解é¤ã¨é£æºããã¿ã¤ãã¼é§åã®ä»çµã¿ãããã£ã¨æ±ç¨çã«å©ç¨ã§ããããã«ãã¦ããããããã¬ããã©ã¸ãªã®é²ç»äºç´ç¨åº¦ã®ãã¨ãå®ç¾ããã®ã«æéã®ãããç¾ç¶ããå°ãã§ãæ¹åãããã®ã ã
timerã³ãã³ãããã¸ã§ã¯ãã®éå§
- æ±ç¨çã«ä½¿ãããã«ã¯ãã¢ããªã±ã¼ã·ã§ã³ã«ããããã³ãã³ãã«ãã¦ãããæ¹ãããã
- ã³ãã³ããªãã»ã¨ãã©ã®ã¹ã¯ãªããè¨èªããç°¡åã«å¼ã³åºããããã¢ããªã±ã¼ã·ã§ã³ã«çµã¿è¾¼ããã¨ãã§ããã
- çæ³ã¯ãcronã®ããã«crontabãå©ç¨ãã¦è¨å®ã§ããã®ããã¹ããªã®ã ããcronã¬ãã«ã®ãã®ãä½ãæè¡ã¯èªåã«ã¯ãªãã
- ãããããã¹ãªã¼ã解é¤ã¨é£æºãããã®ã ãããæ¯æåä½ã®ã¿ã¤ãã¼æ©è½ã¯ä¸è¦ã§ããã
- ãããªã«é »ç¹ã«å®è¡ããããã®ãããã®ãªããã¹ãªã¼ãããªãè¨å®ã«ãã¦ãcronã使ãã°ããã®ã ã
- æ±ããã®ã¯æ¯æ¥åä½ããééã®é·ãã¿ã¤ãã¼æ©è½ã§ããã
- ãããããæ¯å¹´åä½ã®ã¿ã¤ãã¼æ©è½ãä¸è¦ã§ããã
- ãããªã«é·ãééã®ã¿ã¤ãã¼ã§ä½æä½åã¾ã§æå®ããå¿ è¦æ§ã¯ã»ã¨ãã©ãªãã
- ç´ ç´ã«ã«ã¬ã³ãã¼ã«ç¹°ãè¿ãã®äºå®ãå ¥ãã¦ããã°ããã£ã¨æºè¶³ã§ããã
ãã£ã¦ãå¿ è¦ãªã®ã¯æ¥åä½ä»¥ä¸ãå¹´åä½æªæºã®ã¹ãªã¼ã解é¤ã¨é£æºããã¿ã¤ãã¼æ©è½ã§ããã
ã¿ã¤ãã¼ã®è¨å®ãã©ã¼ããã
- ããã¯ããç´ ç´ã«cronãè¦ç¿ãã
- ã§ãcronã»ã©ç´°ããªå¶å¾¡ã¯å¿ è¦ãªãã®ã§ãææ¥ã¨æå»ãæ¥ä»ã¨æå»ã®äºã¤ã®å¼æ°ã¨ããã«ç¶ãã³ãã³ããå®è¡ããããã«ãããã
- æ¯é±æ¥æã®17æããã®J-WAVE ãµã¦ã¸ã»ãµã¦ãã¼ã¸ãé²é³ãããå ´åã¯ã以ä¸ã®ããã«æå®ã§ããã¨è¯ãããã
- 0ãã6ã®æ°åããæ¥ããåã®ææ¥ã«å¯¾å¿ããã
0 1700 /usr/local/bin/rec_radiko.sh -t 3600 FMJ
- ãããããææããéæã¨ããææ°´éãªã©ã®æå®ãcronãè¦ç¿ã£ã¦ãã§ããããã«ãããã
1-5 0600 /usr/local/bin/rec_radiko.sh -t 3600 FMJ 1,3,5 0600 /usr/local/bin/rec_radiko.sh -t 3600 FMJ
- ã¾ããææ¥ã§ãªãæ¥ä»æå®ãããå ´åã¯ãããªæãã
- 2/3ã¯æ¥ææ¥ãªã®ã§ãææ¥0ãæå®ããã¿ã¤ãã¼ã¨åãããµã¦ã¸ã»ãµã¦ãã¼ã¸ãé²é³ãããã¯ãã
2/3 1700 /usr/local/bin/rec_radiko.sh -t 3600 FMJ
- ãã ããææ¥æå®ã¯é±åä½ã®ç¹°ãè¿ãã¿ã¤ãã¼ã ããæ¥ä»æå®ã¯ãã®æ¥éãã®åçºã®ã¿ã¤ãã¼ã¨ãããã
- ãããã¦ããã°ãèªåã®ä½¿ãæ¹ã®ç¯å²ã§ã¯ã»ã¨ãã©ã®æ¬²æ±ãæºãããããã
- é±åä½ã®æå»æå®ã®ç¹°ãè¿ãã¯ãããã©ãæåä½ã®æå»æå®ã®ç¹°ãè¿ãã¯ã»ã¨ãã©ãªãã®ã§ã
- æåä½ã®ç¹°ãè¿ããªããã«ã¬ã³ãã¼ã«ã¤ãã³ããè¨å®ãã¦ããã ãã§ååã¨ããå¤æã
timerã³ãã³ã
- ã¾ãå¿ è¦ã«ãªãã®ã¯ãtimerã³ãã³ãã
- CUIã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ãæä¾ãã¦ãäºç´è¨å®ã®å¦çãè¡ãã®ã ã
- äºç´è¨å®ã¯launchd.plistã«å¤æãããã
- ä¾ãã°ã以ä¸ã®ãããªã³ãã³ãå ¥åã«ãã£ã¦...
timer -e 0 1700 /usr/local/bin/rec_radiko.sh -t 3600 FMJ
- æ¯é±æ¥æã®17æã«èµ·åãããlaunchd.plistãçæããã®ã ã
<?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>Label</key> <string>com.bebekoubou.timer-week 0 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 FMJ</string> <key>ProgramArguments</key> <array> <string>/usr/bin/caffeinate</string> <string>/bin/sh</string> <string>-c</string> <string>/usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 FMJ; /usr/local/bin/timer-sync-wake;</string> </array> <key>StartCalendarInterval</key> <array> <dict> <key>Hour</key> <integer>17</integer> <key>Minute</key> <integer>0</integer> <key>Weekday</key> <integer>0</integer> </dict> </array> </dict> </plist>
- ã¨ãããã¾ã§ã¯ååä½ã£ãradikoã»ãããé²é³å°ç¨ã®rec_radikoru.appã§å®ç¾ã§ãã¦ããã®ã ãã©ã
- timerã³ãã³ãã¯ããã«ã1-5ãã¨ãã1,3,5ããªã©ã®è¤æ°ã®ææ¥æå®ããµãã¼ããã¦ããã
- ããã«ã¯ã2/3ããªã©ã®æ¥ä»æå®ããµãã¼ãããæ¥ä»æå®ã®å ´åã¯ç¹°ãè¿ããªãåçºã®ã¿ã¤ãã¼äºç´ã¨ãã¦ããã
- å°å³ãªæ©è½ã ãã©ããããããã¨ãå®ç¾ããã®ã¯æå¤ã¨é¢åã§ããã
- æ©ã¿ãªããæ¸ããã³ã¼ãã¯ãããªæãã«ãªã£ããï¼200è¡ãããï¼
#!/bin/bash IDENTIFIER=com.bebekoubou.timer weekdays() { safe_chars=`echo $1|sed 's/[^0-9,-\/]//g'` bash_format=`echo $safe_chars|sed 's/\(.-.\)/{\1}/g'|sed 's/-/../g'|tr ',' ' '` bash -c "echo $bash_format"|tr ' ' '\n'|sort -u } formed_args() { m=`echo $1|grep /|cut -d/ -f1|xargs printf %02s` d=`echo $1|grep /|cut -d/ -f2|xargs printf %02s` w=`echo $1|grep -v /` hhmm=`echo $2|sed s/://|xargs printf %04s` cmd=`echo $@|cut -d' ' -f3-` echo -n ${w:-$m/$d} $hhmm $cmd } week_or_date() { echo $1|grep -q / || echo week echo $1|grep -q / && echo date } plist_fname() { echo -n $IDENTIFIER-`week_or_date $1` `formed_args $@|sed 's/\//_/g'` } launchd_path() { echo -n $HOME/Library/LaunchAgents/`plist_fname $@`.plist } plist_Label() { echo -n $IDENTIFIER-`week_or_date $1` `formed_args $@` } plist_StartCalendarInterval_week() { hh=`echo $2|sed s/://|xargs printf %04s|cut -c 1-2` mm=`echo $2|sed s/://|xargs printf %04s|cut -c 3-4` for w in `weekdays $1` do echo "<dict><key>Hour</key><integer>$hh</integer><key>Minute</key><integer>$mm</integer><key>Weekday</key><integer>$w</integer></dict> " done } plist_StartCalendarInterval_date() { m=`echo $1|cut -d/ -f1` d=`echo $1|cut -d/ -f2` hh=`echo $2|sed s/://|xargs printf %04s|cut -c 1-2` mm=`echo $2|sed s/://|xargs printf %04s|cut -c 3-4` echo "<dict><key>Month</key><integer>$m</integer><key>Day</key><integer>$d</integer><key>Hour</key><integer>$hh</integer><key>Minute</key><integer>$mm</integer></dict> " } plist_StartCalendarInterval() { echo $1|grep -q / || plist_StartCalendarInterval_week $@ echo $1|grep -q / && plist_StartCalendarInterval_date $@ } plist_ProgramArguments_week() { shift 2 echo "$@; /usr/local/bin/timer-sync-wake;" } plist_ProgramArguments_date() { launchd_plist=`launchd_path $@` launchd_label=`plist_Label $@` shift 2 echo "$@; rm -f '$launchd_plist'; /usr/local/bin/timer-sync-wake; launchctl remove '$launchd_label'" } plist_ProgramArguments() { echo $1|grep -q / || plist_ProgramArguments_week $@ echo $1|grep -q / && plist_ProgramArguments_date $@ } list_launchd() { echo ======== launchd list >&2 launchd_plist_paths=`ls $HOME/Library/LaunchAgents/$IDENTIFIER* 2>/dev/null` status=$? local IFS=$'\n' for f in $launchd_plist_paths do echo -e `defaults read "${f%.plist}" Label|cut -d' ' -f2-|sed 's/ /\\\t/'`|expand done return $status } list_schedule() { echo ======== schedule list pmset -g sched } add_launchd() { echo ======== edit launchd_plist=`launchd_path $@` defaults write "${launchd_plist%.plist}" Label "`plist_Label $@`" defaults write "${launchd_plist%.plist}" ProgramArguments -array /usr/bin/caffeinate /bin/sh -c "`plist_ProgramArguments $@`" defaults write "${launchd_plist%.plist}" StartCalendarInterval -array `plist_StartCalendarInterval $@` launchctl load "$launchd_plist" echo -e `echo $@|sed 's/ / \\\t/'` } rm_launchd() { echo ======== delete launchd_plist=`launchd_path $@` launchctl unload "$launchd_plist" rm -f "$launchd_plist" echo -e `echo $@|sed 's/ / \\\t/'` } show_usage() { echo "Usage: $COMMAND [-li]" echo " $COMMAND [-de] mm/dd HHMM command; ..." echo " $COMMAND [-de] weeknum HHMM command; ..." echo " mm/dd : 02/01=2/1" echo " weeknum: 0=æ¥ 1=æ 2=ç« 3=æ°´ 4=æ¨ 5=é 6=å 7=æ¥" echo " 1-5 = æããéã¾ã§" echo " 5-7 = éåæ¥" echo " 1,3,5 = ææ°´é" echo " HHMM : 0600=6:00" echo "Example:" echo " $COMMAND -e 02/01 1700 /usr/local/bin/rec_radiko.sh -o radikoru/ -t 3600 FMJ" echo " $COMMAND -d 02/01 1700 /usr/local/bin/rec_radiko.sh -o radikoru/ -t 3600 FMJ" echo " $COMMAND -e 0 1700 /usr/local/bin/rec_radiko.sh -o radikoru/ -t 3600 FMJ" echo " $COMMAND -e 1-5 0600 /usr/local/bin/rec_radiru.sh -o radikoru/ -t 1800 NHK-FM" } command_v() { osascript -e 'delay .5' -e 'tell application "System Events"' -e 'keystroke "v" using command down' -e 'end tell' } cd `dirname $0` COMMAND=`basename $0` # å¼æ°è§£æ while getopts deli OPTION do case $OPTION in d ) OPTION_d="TRUE" ; VALUE_d="$OPTARG" ;; e ) OPTION_e="TRUE" ; VALUE_e="$OPTARG" ;; l ) OPTION_l="TRUE" ;; i ) OPTION_i="TRUE" ;; * ) show_usage ; exit 1 ;; esac done shift $(($OPTIND - 1)) #æ®ãã®éãªãã·ã§ã³ãªå¼æ°ã®ã¿ãã$@ã«è¨å®ããã if [ $# = 0 -a "$OPTION_l" != "TRUE" -a "$OPTION_i" != "TRUE" ]; then show_usage ; exit 1 fi if [ $OPTIND = 1 ]; then echo Needs option!! ; show_usage ; exit 1 fi # ãªãã·ã§ã³å¦ç if [ "$OPTION_d" = "TRUE" ]; then rm_launchd $@ ./timer-sync-wake list_launchd list_schedule fi if [ "$OPTION_e" = "TRUE" ]; then add_launchd $@ ./timer-sync-wake list_launchd list_schedule fi if [ "$OPTION_l" = "TRUE" ]; then list_launchd list_schedule fi if [ "$OPTION_i" = "TRUE" ]; then list_launchd &>/dev/null || exit 1 list_launchd 2>/dev/null|nl -s': ' read -p 'Select Number :' NUM echo -n $NUM|grep -q '[0-9]\{1,\}' || exit 1 [ $NUM -gt `list_launchd 2>/dev/null|wc -l` ] && exit 1 command_args=`list_launchd 2>/dev/null|head -$NUM|tail -1|sed 's/ \{2,\}/ /'` read -p '[c]opy [d]elete :' ACTION case $ACTION in c) echo -en "$0 -e $command_args"|pbcopy command_v & ;; d) rm_launchd $command_args ./timer-sync-wake list_launchd list_schedule ;; *) exit 1;; esac fi
ã¹ãªã¼ã解é¤ãé£æºãããtimer-sync-wakeã³ãã³ã
- è¨å®ããlaunchd.plistã¯ãpmset scheduleã¨é£æºããããã¨ã§ãäºç´ããæå»ã«ã¹ãªã¼ãã解é¤ãããæå®ããã³ãã³ããå®è¡ãããä»çµã¿ã
- ç¹°ãè¿ãè¨å®ãã§ããªãpmset scheduleããæ¯é±ç¹°ãè¿ãã®launchd.plistã¨é£æºããããããlaunchd.plistã«è¨å®ããå¦çã®æå¾ã§ã次é±ã®pmset scheduleãè¨å®ãã¦ããã
- ãã®launchd.plistã¨pmset scheduleã®è¨å®ãåæãããä»äºãããã®ãããã®timer-sync-wakeã³ãã³ãã§ããã
- timerã³ãã³ãã§æå®ãããææ¥æå®ã®äºç´å¦çã¯ãlaunchd.plistã«å¤æãããéã«ããã®æå¾ã«å¿ ããã®timer-sync-wakeã³ãã³ããä»å ãããã
- timer-sync-wakeã³ãã³ãã«ãã£ã¦ã次ã«å¿ è¦ãªpmset scheduleãè¨å®ããã次é±ã®äºç´æ¥æã®ã¹ãªã¼ã解é¤ã«åããã®ã§ããã
- 以ä¸ã®å¦çã¯ãtimerã³ãã³ãã§äºç´ããæã«èªåçã«è¨å®ãããã®ã§ãã¦ã¼ã¶ã¼èªããtimer-sync-wakeã³ãã³ããå®è¡ããå¿ è¦æ§ã¯ãªãã®ã§ããã
#!/bin/sh IDENTIFIER=com.bebekoubou.timer pmdate_from_w_hhmm() { w=`expr $1 % 7` hh=`echo $2|sed s/://|xargs printf %04s|cut -c 1-2` mm=`echo $2|sed s/://|xargs printf %04s|cut -c 3-4` current_date=`date +%s` preset_date=`date -v${w}w -v${hh}H -v${mm}M -v0S +%s` n=`expr $current_date / $preset_date` date -v${w}w -v+${n}w -v${hh}H -v${mm}M -v0S -v-30S "+%m/%d/%y %H:%M:%S" } pmdate_from_md_hhmm() { m=`echo $1|cut -d/ -f1` d=`echo $1|cut -d/ -f2` hh=`echo $2|sed s/://|xargs printf %04s|cut -c 1-2` mm=`echo $2|sed s/://|xargs printf %04s|cut -c 3-4` current_date=`date +%s` preset_date=`date -v${m}m -v${d}d -v${hh}H -v${mm}M -v0S +%s` n=`expr $current_date / $preset_date` date -v+${n}y -v${m}m -v${d}d -v${hh}H -v${mm}M -v0S -v-30S "+%m/%d/%y %H:%M:%S" } add_schedule() { pmset -g sched|grep -q "wake at $1" || ./timer-add-schedule "$1" } rm_schedule() { pmset -g sched|grep -q "wake at $1" && ./timer-rm-schedule "$1" } weekdays() { safe_chars=`echo $1|sed 's/[^0-9,-\/]//g'` bash_format=`echo $safe_chars|sed 's/\(.-.\)/{\1}/g'|sed 's/-/../g'|tr ',' ' '` bash -c "echo $bash_format"|tr ' ' '\n'|sort -u } echo ======== sync-wake cd `dirname $0` _IFS="$IFS"; IFS=$'\n'; # launchd.plistãè¦ã¦ãä¸è¶³ããscheduleã追å ãã launchd_plist_paths="`ls $HOME/Library/LaunchAgents/$IDENTIFIER* 2>/dev/null`" for f in $launchd_plist_paths do args=`defaults read "${f%.plist}" Label` word=`echo $args|cut -d' ' -f2` hhmm=`echo $args|cut -d' ' -f3` for wd in `weekdays $word` do if `echo $wd|grep -q /`; then pmdate=`pmdate_from_md_hhmm $wd $hhmm` else pmdate=`pmdate_from_w_hhmm $wd $hhmm` fi add_schedule "$pmdate" launchd_pmdate_list+="${pmdate}\n" done done # launchd.plistã«åå¨ããªããä½åãªscheduleãåé¤ãã schedule_wake_list=`pmset -g sched|grep '^\W\['|grep 'wake at'|cut -d' ' -f6-7` for s in $schedule_wake_list do echo $launchd_pmdate_list|grep -q "$s" || rm_schedule "$s" done IFS="$_IFS"
ãã®æ¥éãã®åçºäºç´ã«ããæ¹æ³
- ä»åº¦ã¯éã«æ¥ä»æå®ã®ç¹°ãè¿ããªãäºç´ãè¨å®ããªãã¦ã¯ãªããªãã
- launchdã®StartCalendarIntervalã¯ä¸æ¦è¨å®ãloadãããã¨ããã®è¨å®ãããéããæ°¸é ã«ç¹°ãè¿ãã
- ä¾ãã°2æ3æ¥ãè¨å®ãã¦ããã¨ãããã¯æ¯å¹´ç¹°ãè¿ããããã¨ã«ãªãã
- ãã®ç¹°ãè¿ããæ¢ããããã«ãäºç´å¦çã®æå¾ã§unloadãã¦ãä¸è¦ã«ãªã£ãlaunchd.plistãåé¤ãããã¨ããã
- ã¨ããããlaunchd.plistã«ãã£ã¦èµ·åãããå¦çAã®ä¸ã§ããã®launchd.plistãunloadãã¦ãã¾ãã¨ãunloadããç¬éã«ãã®å¦çAãä¸æ¢ããã¦ãã¾ããããªã®ã ã
- ãã®å¾ã«ç¶ãlaunchd.plistã®åé¤ã®å¦çãå®è¡ãããããã£ã¨æ®ã£ãã¾ã¾ã«ãªã£ã¦ãã¾ã...ã
- ä¸æ¹ãunloadããããã«ã¯ããã®è¨å®ãã¡ã¤ã«ã§ããlaunchd.plistãå¿ è¦ã§ãããå ã«åé¤ãã¦ãã¾ãã¨unloadãã§ããªããªãã
- ãããªãåé¤ããlaunchd.plistã¨ã¯ç¡é¢ä¿ã®ãå®æçã«ç£è¦ãã¦åé¤ããå¦çBã追å ãããããªãã...ã¨æ©ãã§ããããlauncdctlã®ä¸ã«removeããããã¨ã«æ°ä»ããï¼
- removeãªãã稼åä¸ã®ã¸ã§ããLabelæå®ã§åé¤ã§ãããå ã«launchd.plistãåé¤ãã¦ãã¾ã£ã¦ãOKã
timer -e 02/03 1700 /usr/local/bin/rec_radiko.sh -t 3600 FMJ
- ä¾ãã°ã2/3ã®1700ã®ã¿ã¤ãã¼äºç´ãããã¨ã以ä¸ã®ãããªlaunchd.plistãçæããã°è¯ãã®ã§ããã
<?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>Label</key> <string>com.bebekoubou.timer-date 02/03 1700 /usr/local/bin/rec_radiko.sh -t 3600 FMJ</string> <key>ProgramArguments</key> <array> <string>/usr/bin/caffeinate</string> <string>/bin/sh</string> <string>-c</string> <string>/usr/local/bin/rec_radiko.sh -t 3600 FMJ; rm -f '/Users/zari/Library/LaunchAgents/com.bebekoubou.timer-date 02_03 1700 _usr_local_bin_rec_radiko.sh -t 3600 FMJ.plist'; /usr/local/bin/timer-sync-wake; launchctl remove 'com.bebekoubou.timer-date 02/03 1700 /usr/local/bin/rec_radiko.sh -t 3600 FMJ'</string> </array> <key>StartCalendarInterval</key> <array> <dict> <key>Day</key> <integer>3</integer> <key>Hour</key> <integer>17</integer> <key>Minute</key> <integer>0</integer> <key>Month</key> <integer>2</integer> </dict> </array> </dict> </plist>
ããã§ã²ã¨ã¾ããäºç´ããæå»ã«ãªã£ãããã¡ããã¨ã¹ãªã¼ãã解é¤ãã¦ãã³ãã³ããå®è¡ããtimerã³ãã³ãã®åºæ¥ä¸ããï¼
rec_radikoru.shã³ãã³ã
- radikoã¨ãããâ ãããã§äºã¤ã®ã·ã§ã«ã¹ã¯ãªããã使ãåããã®ã¯é¢åã ã
- ãã¤ãNHK-FMãrec_radiko.shã§é¸å±ãã¦ãã¾ã£ã¦ããã¨ã§é²é³ã§ãã¦ããªãã¦ãã¬ãã«ãªãããã¨å¿ è³ã
- radikoã¨ãããâ ããããè³¢ã使ãåããrec_radikoru.shã¨ããã©ããã¼ã¹ã¯ãªãããä½ããã¨ã«ããã
- ã¤ãã§ã«ããã®å°åã§è¦è´å¯è½ãªã©ã¸ãªå±ã®ä¸è¦§ã表示ããæ©è½ã欲ããããã£ã¦ããããªã³ã¼ãã«ãªã£ãã
#!/bin/bash cd `dirname $0` while getopts l OPTION do case $OPTION in l ) OPTION_l="TRUE" ;; esac done if [ "$OPTION_l" = "TRUE" ]; then areaid=`/usr/local/bin/rec_radiko.sh -a|tail -1|cut -d, -f1` station_names=`echo ---- NAME ----,NHK-R1,NHK-R2,NHK-FM,` station_names+=`curl -s http://radiko.jp/v2/station/list/$areaid.xml|xpath //name 2>/dev/null|sed -e 's/<name>//g' -e 's/<\\/name>/,/g'` station_ids=`echo ---- ID ----,NHK-R1,NHK-R2,NHK-FM,` station_ids+=`curl -s http://radiko.jp/v2/station/list/$areaid.xml|xpath //id 2>/dev/null|sed -e 's/<id>//g' -e 's/<\/id>/,/g'` paste <(echo $station_ids|tr ',' '\n') <(echo $station_names|tr ',' '\n')|expand -t 16 exit 0 fi echo $@|grep 'NHK-\(R1\|R2\|FM\)$' && ./rec_radiru.sh $@ echo $@|grep 'NHK-\(R1\|R2\|FM\)$' || ./rec_radiko.sh $@
- ã©ã¸ãªå±ã®ä¸è¦§ã¯-lãªãã·ã§ã³ãæå®ããã®ã ã
$ rec_radikoru.sh -l ---- ID ---- ---- NAME ---- NHK-R1 NHK-R1 NHK-R2 NHK-R2 NHK-FM NHK-FM TBS TBSã©ã¸ãª QRR æåæ¾é LFR ãããã³æ¾é RN1 ã©ã¸ãªNIKKEI第1 RN2 ã©ã¸ãªNIKKEI第2 INT InterFM FMT TOKYO FM FMJ J-WAVE JORF ã©ã¸ãªæ¥æ¬ BAYFM78 bayfm78 NACK5 NACK5 YFM Fï¼ã¨ã³ãã HOUSOU-DAIGAKU æ¾é大å¦
ãã¦ã³ãã¼ãã¨ã¤ã³ã¹ãã¼ã«
éçºï¼å©ç¨ç°å¢
- OSX10.8.2
- bash -version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12) Copyright (C) 2007 Free Software Foundation, Inc.
timerã³ãã³ã
- timer0.1.zipããã¦ã³ãã¼ãããã
-
- ææ°çï¼https://github.com/zarigani/timer
- 解åããããinstall.shãå®è¡ããã
- ããã©ã«ãã¯ã/usr/local/binã«ã¤ã³ã¹ãã¼ã«ãããã
- å¼æ°ã§ãã¹ãæå®ããã¨ãæå®ãããã£ã¬ã¯ããªã«ã¤ã³ã¹ãã¼ã«ãããã
-
radikoããããâ ããããé²é³ããå ´å
- radikoru0.1.zipããã¦ã³ãã¼ãããã
-
- ææ°çï¼https://github.com/zarigani/radikoru
- 解åããããinstall.shãå®è¡ããã
- ããã©ã«ãã¯ã/usr/local/binã«ã¤ã³ã¹ãã¼ã«ãããã
- å¼æ°ã§ãã¹ãæå®ããã¨ãæå®ãããã£ã¬ã¯ããªã«ã¤ã³ã¹ãã¼ã«ãããã
-
- Xcodeãã¤ã³ã¹ãã¼ã«ãã¦ãPreferences... >> Downloads >> Components >> Command Line Tools ãã¤ã³ã¹ãã¼ã«ãã¦ããã
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" $ brew install wget $ brew install swftools $ brew install rtmpdump $ brew install ffmpeg
- ããã«ãrtmpdump2.4ï¼ãã¤ããªçï¼ããã¦ã³ãã¼ããã¦ãã¤ã³ã¹ãã¼ã«ã
使ãæ¹
以ä¸ããã¹ã¦ã®ã¹ã¯ãªããã/usr/local/binã«ã¤ã³ã¹ãã¼ã«ãã¦ã/usr/local/binãã³ãã³ããµã¼ããã¹ã«ãªã£ã¦ããbashç°å¢ã
- 2件ã®äºç´ã追å ããã
$ timer -e 02/10 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 NHK-FM $ timer -e 0 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 FMJ
- ç¾å¨ã®äºç´ãªã¹ãã表示ãããï¼-l=ãªã¹ãã®Lï¼
$ timer -l ======== launchd list 02/10 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 NHK-FM 0 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 FMJ ======== schedule list Repeating power events: wakepoweron at 0:00AM every day Scheduled power events: [0] wake at 02/10/13 16:59:30
- 対話ã¢ã¼ãï¼-i=ã¤ã³ã¿ã©ã¯ãã£ãã®iï¼
- 対象ã®ã¿ã¤ãã¼äºç´ãçªå·ã§æå®ãã¦ã
- (c)ã³ãã¼ãã(d)åé¤ããé¸æããã
$ timer -i 1: 02/10 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 NHK-FM 2: 0 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 FMJ Select Number :1 [c]opy [d]elete :
- æ¢åã®ã¿ã¤ãã¼äºç´ãä¿®æ£ããå ´åã¯...
- (c)ã³ãã¼ãã¦ä¿®æ£ãã
- ãã®å¾ãå¤ãã¿ã¤ãã¼äºç´ã(d)åé¤ããã®ã ã
ä¾
timer -e 0 1700 /usr/local/bin/rec_radikoru.sh -o radikoru/ -t 3600 FMJ
- æ¯é±æ¥æã®17:00ããJ-WAVEã1æéé²é³ããã
timer -e 1-5 0515 open -a iTunes /Users/zari/Music/iTunes/iTunes\ Music/Unknown\ Artist/Unknown\ Album/J-WAVE_20130203-1701.m4a
- æ¯é±ææããéæã®æ5æ15åã«ãiTunesã§ãé²é³ãããµã¦ã¸ã»ãµã¦ãã¼ã¸ãç®è¦ã¾ã代ããã«åçããã
- ããªã¥ã¼ã ï¼ã·ã¹ãã ãµã¦ã³ãã¨iTunesã®è¨å®ã«å½±é¿ããããåçæéï¼åæ¢ããã¾ã§ã
timer -e 1-5 0515 afplay -v 200 -t 300 /Users/zari/Music/iTunes/iTunes\ Music/Unknown\ Artist/Unknown\ Album/J-WAVE_20130203-1701.m4a
- æ¯é±ææããéæã®æ5æ15åã«ãafplayã³ãã³ãã§ãé²é³ãããµã¦ã¸ã»ãµã¦ãã¼ã¸ãç®è¦ã¾ã代ããã«åçããã
- ããªã¥ã¼ã ï¼200ãåçæéï¼300ç§ï¼5åã
timer -e 1-5 0515 osascript -e 'tell application "iTunes"' -e 'set sound volume to 100' -e 'play playlist "ãããã¬ã¼ã"' -e 'delay 60' -e 'stop' -e 'end tell'
- æ¯é±ææããéæã®æ5æ15åã«ãAppleScriptã§iTunesã®ãããã¬ã¼ããé¸æãã¦ãç®è¦ã¾ã代ããã«åçããã
- ããªã¥ã¼ã ï¼iTunesããªã¥ã¼ã =100ï¼ã·ã¹ãã ãµã¦ã³ãã¯æªè¨å®ãªã®ã§æ¢åã®è¨å®ã«å½±é¿ãããï¼ãåçæéï¼60ç§
- iTunesã§ã·ã£ããã«ã®è¨å®ããã¦ããã°ãæ¯æéãé³æ¥½ãè´ããã
timer -e 1-5 0515 osascript /Users/zari/Library/Scripts/timer_sample.scpt
- ããã«é·ãAppleScriptã³ã¼ãã§ããã°ããã¡ã¤ã«ã«ä¿åãã¦ããããããtimerèµ·åæã«å®è¡ãããã¨ãã§ããã
- AppleScriptãå®è¡ã§ããã¨ãããã¨ã¯ãããã¦ãã®ãã¨ã¯timerã³ãã³ãããå®è¡ã§ããã®ã ã
*1:StationTVãªã©ã®TVè¦è´å°ç¨ã®ã¢ããªã±ã¼ã·ã§ã³ãªããäºç´é²ç»ã¯ã¹ãªã¼ã解é¤ã¨é£åãã¦å®è¡ããããããã¨åããã¨ãTVã®é²ç»ã«éãããä¸è¬çãªå¦çãã¹ã¦ã«ããã¦äºç´æ¥æã«å®è¡ã§ããããã«ãããã®ã ã