让Windows定点报时:VBscript

有很多定点报时的软件啦,不过我需要的很简单,就是定时报个时。而大多数这样的软件,广告满天飞,例如毒瘤bd和365-5。除了毒性之外,也就是太不和我的需求了,大多数项目的产生都是现有的软件或者已有的代码无法符需求,骂完煞笔,只有自己手动写。我是菜鸟,上面的理论是意淫的。
算然简单,但是也是有步骤的

第一步

新建一个文本文件,例如使用Sublime Text/Lime Text/Atom/Edit Plus/Notepad++等打开,输入下面的,保存为有效的执行文件。

Dim speaks, speech, phrase
speaks = Hour(Time)
Set speech=CreateObject("sapi.spvoice") 
If speaks > 0 Then
    If speaks < 7 Then
       phrase = " before dusk."
       speech.Speak "It is now " & speaks & " o'clock" & phrase
    ElseIf speaks < 11 Then
        phrase = "Good Morning, "
        speech.Speak phrase & "it's now " & speaks & " o'clock."
    ElseIf speaks < 14 Then
        phrase = " at noon."
        speech.Speak "It is now " & (speaks MOD 12) & " o'clock" & phrase
    ElseIf speaks < 18 Then
        phrase = "Good afternoon, "
        speech.Speak phrase & "it's now " & (speaks v 12) & " o'clock."
    ElseIf speaks < 23 Then
        phrase = "Good Evening, "
        speech.Speak phrase & "it's now " & (speaks MOD 12) & " o'clock."
    Else
        phrase = "Midnight, "
        speech.Speak phrase & "it's now " & (speaks MOD 12) & " o'clock."
    End If

上面的是一个简单版的speakTime,使用If/ElseIf来判断。首先获取当前的小时,使用Hour()方法,接受的参数Time。

也可以使用口头版(中文)

'Relative to the nearest time point
Function getFloorCellRelativeMinute(hour)
    minutes_passed = Minute(Time)
    If minutes_passed = 0 Then
      minutes_say = hour & "点"
    ElseIf minutes_passed <= 5 Then
        minutes_say = hour & "点过" & minutes_passed & "分"
    ElseIf minutes_passed < 7 Then
        minutes_say = hour & "点刚过5分"
    ElseIf minutes_passed < 10 Then
        minutes_say = "岔" & (10 - minutes_passed) & "分钟," & hour & "点10分"
    ElseIf minutes_passed < 12 Then
        minutes_say = "刚过" & hour & "点10分"
    ElseIf minutes_passed < 15 Then
        minutes_say = "岔" & (15 - minutes_passed) & "分钟," & hour & "点一刻"
    ElseIf minutes_passed = 15 Then
        minutes_say = hour & "点一刻"
    ElseIf minutes_passed < 17 Then
        minutes_say = "刚过" & hour & "点一刻"
    ElseIf minutes_passed < 20 Then
        minutes_say = "岔" & (20 - minutes_passed) & "分钟," & hour & "点20"
    ElseIf minutes_passed < 30 Then
        minutes_say = "岔" & (30 - minutes_passed) & "分钟," & hour & "点半"
    ElseIf minutes_passed = 30 Then
        minutes_say = hour & "点半"
    ElseIf minutes_passed < 36 Then
        minutes_say = hour & "点半过" & (minutes_passed - 30) & "分钟"
    ElseIf minutes_passed < 45 Then
        minutes_say = "岔" & (45 - minutes_passed) & "分钟," & hour & "点45"
    ElseIf minutes_passed = 45 Then
        minutes_say = hour & "点45"
    ElseIf minutes_passed < 50 Then
        minutes_say = "岔" & (50 - minutes_passed) & "分钟," & hour & "点50"
    ElseIf minutes_passed < 60 Then
        minutes_say = "岔" & (60 - minutes_passed) & "分钟," & (hour + 1) & "点"
    Else
        minutes_say =  hour & "点" & minutes_passed & "分"
    End If
    getFloorCellRelativeMinute = minutes_say
End Function

Function getHour(style)
    hours = Hour(Time)
    If style = 12 Then
      If hours < 13 Then
          hours_say =  hours
      Else
          hours_say =  hours MOD 12
      End If
      getHour = hours_say
    ElseIf style = 24 Then
      getHour = hours
    End If
End Function

Sub speakTime(style)
    Dim hour, minute, speech
    hour = getHour(style)
    minute = getFloorCellRelativeMinute(hour)

    Set speech = CreateObject("sapi.spvoice")
    speech.Speak(minute)
End Sub
Dim arg
arg = Wscript.Arguments.Item(0)
If arg = 12 Then
    speakTime(12)
ElseIf arg = 24 Then
    speakTime(24)
End If

上面的是使用谐音,因为“差”在这里读作“chai”

二 添加到 task scheduler

打开 task scheduler, 在 task schedular library右键新建一个文件夹“User”,新建一个任务,

让Windows定点报时:VBscript_第1张图片
Create new Task

Triggers的Advanced settings中可以选择repeat task every。以及初始时间 上面的settings的Start开始

让Windows定点报时:VBscript_第2张图片
Speak Time Properties
让Windows定点报时:VBscript_第3张图片
Triggers Tab of Speak Time Properties
让Windows定点报时:VBscript_第4张图片
Action Tab of Speak Time Properties

你可能感兴趣的:(让Windows定点报时:VBscript)