9 10 11 12 13 14 function fizzBuzz(n) local line = string.format('%d: ', n) if n % 3 == 0 then line = line .. 'Fizz' end if n % 5 == 0 then line = line .. 'Buzz' end print(line) end for i = 1, 100 do fizzBuzz(i) end
10 11 12 13 14 15 16 useWatcher = hs.usb.watcher.new(function(usb) if usb['eventType'] == 'added' then local syn = hs.speech.new('kyoko') if usb['productName'] == 'Arduino Micro' then syn:pitch(250) syn:speak('ぼく、アルディーノ!!アルディーノ アイディーイーを起動するね!') hs.application.launchOrFocus('Arduino') elseif usb['productName'] == 'USB FLASH DRIVE' then syn:pitch(80) syn:speak('ぼく、ユーエスビードライブ!!ファインダーを起動するね!') hs.application.launchOrFocus('Finder') local finder = hs.appfinder.appFromName('Finder') finder:selectMenuItem({ 'File', 'New Finder Window' }) end end end):start()
10 11 12 lastBatteryPowerSource = '' batteryWatcher = hs.battery.watcher.new(function() local powerSource = hs.battery.powerSource() local percentage = hs.battery.percentage() if lastBatteryPowerSource ~= powerSource and powerSource == 'Battery Power' then local syn = hs.speech.new('kyoko') syn:pitch(100) syn:speak(string.format('充電はあと%dパーセントだよ。気をつけてね!', percentage)) end lastBatteryPowerSource = powerSource end):start()