Applescript Speak Time and date

Apple Script: At your service.

set x to output volume of (get volume settings)


set current_volume to output volume of (get volume settings)

if current_volume is less than 90 then

set current_volume to 90

end if


tell application "iTunes" to pause

set volume output volume current_volume


try

say "At your service, Sir." using "Vicki"

say "Now is... " using "Vicki"

say time string of (current date) using "Vicki"

say date string of (current date) using "Vicki"

end try

set volume output volume x



  1. 設定變數x記錄目前的輸出音量
  2. 設定變數current_volume取得目前音量設定
  3. 如果current_volume音量值低於90的話
  4. 就將current_volume音量值調成90
  5. 將iTunes暫停(以免你的耳朵被震壞,但開機沒這煩惱,此段可刪)
  6. 將輸出音量調整到current_volume值
  7. 執行try
  8. 維琪:「At your service, Sir.」
  9. 維琪:「Now is...」
  10. 維琪:「時間(取得時間變數)」
  11. 維琪:「日期(取得日期變數)」
  12. 結束try
  13. 將輸出音量調整為最初音量值x

音量值的範圍位於0~100,通常你如果有使用鬧鐘軟體,他們都會將叮咚的聲音使用最大聲100,但我戴耳機的時候只能忍受到90,所以用這個值作為是否要調整目前音量的依據。

其實報時的句子可以利用「&」符號結合文字字串,那為什麼我還要分成多行執行呢?原因在於Vicki不知為啥在連成一串時會將時間日期逐一當成數字唸出,你就會聽到「0.6.1.3.2.0.1.0....」之類的,甚至將秒數精確唸到小數點第六位。分成多行可以讓電腦發出理想的句子,聽起來會更像真人。




你可以將儲存成應用程式,並設定開機項目(System Preferences/ Accounts/ Login items)中自動開啟。登入電腦時就會進行報時的功能,還挺有感覺的。


Ref.
  1. CalvinX, “Volume Script,” MacScripter, 五月 8, 2005, http://macscripter.net/viewtopic.php?pid=72265.
  2. HexMonkey, “AppleScript System Events Volume Help,” MacRumors, 八月 19, 2005, http://forums.macrumors.com/showthread.php?t=144749.
  3. “AppleScript variables,” Satimage, 2008, http://www.satimage.fr/software/en/tutorial/tutorial_as2.html.
  4. Adam Bell, “Dates & Times in AppleScripts,” MacScripter, 七月 23, 2007, http://macscripter.net/viewtopic.php?id=24737.

小泉

喜愛用文字說明自己眼中所見的一切

張貼留言

較新的 較舊

نموذج الاتصال