目覚まし時報
【概要】
Macの起動時に、
時報と音楽とで「目覚まし時計」の代わりをするアップルスクリプト。
デフォルトでは、1分ごとに女性の声で時間を知らせてくれます。
通常の目覚まし時計みたいには、うるさく感じないはずです。
まだ未完成ですが、いつ完成するのか分からないのと、
とりあえずは、現状のままでも使用できるので、
公開してしまいます。
作りも、どういう仕様にするか試行錯誤しながら作成したものなので、
かなり雑なスクリプトになっています。
【下準備】 おそらくOSX10.7以上で使用可能。
システム環境設定 > 省エネルギー > スケジュール > 起動またはスリープ解除で起動時間を設定。
次に、
システム環境設定 > 音声入力と読み上げ >
テキスト読み上げ > システムの声 > 「Kyoko」が選択できるか確認。
「Kyoko」が無ければ、カスタマイズで「Kyoko」にチェックを入れます。
▼AppleScriptコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
property StartHours : 7 --稼働時間帯の開始時間(単位:時) property EndHours : 10 --稼働時間帯の終了時間(単位:時) property StartVolume : "1.2" --音量1~7の値 property StopDialog : "ON" --ストップダイアログ property TimeInterval : 1 --時報間隔1~30の整数(単位:分) property TimeSignalCount : 0 --時報回数初期値0 property mySelectPlaylist : "" property myPlaylist : "" on run --delay 30 set volume StartVolume set TimeSignalCount to 0 --時報回数初期化 set NOWhours to hours of (current date) -- 時間を取得 set NOWminutes to minutes of (current date) -- 分を取得 if StartHours > EndHours then if ((StartHours ≤ NOWhours) and (NOWhours ≤ 23)) or ((0 ≤ NOWhours) and (NOWhours ≤ EndHours)) then main() of me end if else if (StartHours ≤ NOWhours) and (NOWhours ≤ EndHours) then --稼働時間帯 main() of me else main2() of me quit end if end run on idle set TimeSignalCount to TimeSignalCount + 1 set upTimimg to (TimeSignalCount mod 20) --20回毎に0.2アップ set upVolume to 0 if upTimimg = 0 then set upVolume to (0.02 * TimeSignalCount) if (TimeSignalCount > 60) then set upVolume to 0 --最大音量アップ値=1 50回超えたら音量アップを止める。 set volume ((OriginalVolume() of me) + upVolume) if mySelectPlaylist is false then quit else set NOWhours to hours of (current date) -- 時間を取得 set NOWminutes to minutes of (current date) -- 分を取得 if StartHours > EndHours then if ((StartHours ≤ NOWhours) and (NOWhours ≤ 23)) or ((0 ≤ NOWhours) and (NOWhours ≤ EndHours)) then TimeSignal(NOWhours, NOWminutes) of me end if else if (StartHours ≤ NOWhours) and (NOWhours ≤ EndHours) then --稼働時間帯 TimeSignal(NOWhours, NOWminutes) of me else quit --------稼働時間帯ではない場合は、スクリプト終了。 end if end if return 1 end idle on StartMusic() --音楽開始処理 try tell application "iTunes" --set mySelectPlaylist to (choose from list (name of every playlist as list) with prompt "プレイリストを選択して下さい:" & return & "再生を停止する場合は[キャンセル]を。") if mySelectPlaylist is in (name of every playlist as list) then try set myPlaylist to playlist (mySelectPlaylist as string) play myPlaylist end try else if mySelectPlaylist is "" then --activate --display dialog "プレイリストが選択されていません。" & return & return & "音楽は流れません。" buttons {"OK"} default button 1 giving up after 10 with icon 0 else --activate --display dialog "選択したプレイリストが、" & return & "iTunesのプレイリストにありませんでした。" & return & return & "音楽は流れません。" buttons {"OK"} default button 1 giving up after 10 with icon 0 end if end tell end try end StartMusic on SelectPlaylist() --プレイリスト選択 tell application "iTunes" activate set mySelectPlaylist to (choose from list (name of every playlist as list) with prompt "プレイリストを選択して下さい。") if mySelectPlaylist is false then activate display dialog "スクリプトはキャンセルされました。" & return & return buttons {"OK"} default button 1 giving up after 10 with icon 0 else set myPlaylist to playlist (mySelectPlaylist as string) end if end tell return myPlaylist end SelectPlaylist on makeFN(aNum) --2桁にする set aText to "00" & (aNum as text) set aLen to length of aText set aRes to text (aLen - 1) thru -1 of aText return aRes end makeFN on main() if mySelectPlaylist = "" then set myPlaylistName to "------ No Lsit ------" else set myPlaylistName to mySelectPlaylist as Unicode text end if set msg1 to "▽前回のiTunesのプレイリスト▽" & return & myPlaylistName & return & return set msg1 to msg1 & "▽現在の音量▽" & return & "--- " & (OriginalVolume()) & " ---" & return & return set msg1 to msg1 & "iTunesのプレイリストから音楽を選択しますか?" & return & return set msg1 to msg1 & "何も操作をしない場合、" & return & "30秒後に、前回使用した音楽が流れます。" activate set ans1 to display dialog msg1 buttons {"時報のみ", "中止", "音楽選択"} default button 3 giving up after 30 with icon 1 if button returned of ans1 = "音楽選択" then tell application "iTunes" to launch SelectPlaylist() of me tell application "Finder" to set visible of processes whose name is "iTunes" to false StartMusic() of me else if button returned of ans1 = "変更なし" then StartMusic() of me else if button returned of ans1 = "時報のみ" then set mySelectPlaylist to "" set myPlaylist to "" else if button returned of ans1 = "中止" then quit else StartMusic() of me end if end main on main2() if mySelectPlaylist = "" then set myPlaylistName to "------ No Lsit ------" else set myPlaylistName to mySelectPlaylist as Unicode text end if set msg1 to "■■■■■ 現在の時間帯は、■■■■■" & return & "■■■■■ 設定のみ可能です。■■■■■" & return & return & return set msg1 to msg1 & "▽前回のiTunesのプレイリスト▽" & return & myPlaylistName & return & return set msg1 to msg1 & "▽現在の音量▽" & return & "--- " & (OriginalVolume()) & " ---" & return & return set msg1 to msg1 & "iTunesのプレイリストから音楽を選択しますか?" & return set msg1 to msg1 & "何も操作をしない場合、" & return & "30秒後に、この表示は消えます。" activate set ans1 to display dialog msg1 buttons {"時報のみ", "中止", "音楽選択"} default button 3 giving up after 30 with icon 1 if button returned of ans1 = "音楽選択" then tell application "iTunes" to launch SelectPlaylist() of me tell application "Finder" to set visible of processes whose name is "iTunes" to false else if button returned of ans1 = "変更なし" then else if button returned of ans1 = "時報のみ" then set mySelectPlaylist to "" set myPlaylist to "" else if button returned of ans1 = "中止" then quit end if quit end main2 on TimeSignal(NOWhours, NOWminutes) if ((TimeInterval as integer) = 0) or ((TimeInterval as integer) > 30) then set TimeInterval to 1 --時報インターバル if (NOWminutes mod (TimeInterval as integer)) = 0 then --分単位 set oldVolume to (OriginalVolume() of me) as number set volume ((oldVolume) + 0.3 as number) -- 音声用に一時的に、音量を上げる。 try say (NOWhours as Unicode text) & "時、" & (NOWminutes as Unicode text) & "分です。" speaking rate 170 using "Kyoko" end try set volume oldVolume as number end if if StopDialog = "ON" then --ダイアログ表示 set NOWminutes00 to makeFN(NOWminutes) of me tell application "System Events" key code 53 --escキー end tell --with timeout of 53 seconds activate set ans2 to display dialog "目覚まし時報を続けますか?" & return & "現在の音量 ▷ " & OriginalVolume() & return & return & "▷▷▷▷▷ " & (NOWhours as Unicode text) & "時" & (NOWminutes00 as Unicode text) & "分" & return & "" buttons {"続ける", "止める"} default button 2 giving up after 59 with icon 1 if button returned of ans2 = "続ける" then else if button returned of ans2 = "止める" then quit end if --end timeout else delay 59 end if end TimeSignal on OriginalVolume() set getvolume to get volume settings set outVol to output volume of getvolume set myVol to outVol / (100 / 7) return myVol end OriginalVolume |
【作成方法】
ユーティリティ > AppleScript エディタを起動。
上のAppleScriptコードを入力して保存。
保存形式は、アプリケーションでハンドラの実行後に終了しないにチェックを入れます。
アプリケーションが完成したら、
Dockに登録して、ログイン時に開くにチェックを入れます。
これでMac起動時に自動で起動し、
目覚まし代わりになります。
【設定】
とりあえずは、AppleScriptコードの上から3つの項目だけを、
環境に合わせて「数値」を変えていけばいいと思います。
property StartHours : 7 –稼働時間帯の開始時間(単位:時)
property EndHours : 10 –稼働時間帯の終了時間(単位:時)
property StartVolume : “1.2” –音量1~7の値
▼アプリケーション起動画面
【注意点】
時報の時間は、最大1分の誤差があります。
スリープ防止に、Escキーを使用しています。
時間によっては、時報が一部、英語の発音になります。(OSXの仕様?)