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