You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Name: Night Shift// Description: Control Night Shift on macOS// Author: Pavel 'Strajk' Dolecek// Acknowledgements:// - https://github.com/smudge/nightlight// - https://github.com/shmulvad/alfred-nightshift/// Notes:// nightlight CLI usage:// on/off: `nightlight on|off|toggle`, status will show current state// temp: `nightlight temp [0-100]`, no argument will show current temperature// schedule: `nightlight schedule [start|off|HH:MM HH:MM]`import"@johnlindquist/kit"import{Choice}from"@johnlindquist/kit";asyncfunctionmain(){awaitexeca('which',['nightlight']).catch(async()=>{letchoice=awaitarg({placeholder: `Nightlight CLI required, but not installed, install?`,choices: ['Yes','No']})if(choice!=='Yes'){awaitnotify(`OK, not installing Nightlight CLI & exiting`)exit()// exit whole script}console.log(`Installing Nightlight CLI... on Apple Silicon it might take a while because precompiled binaries are not available yet, see https://github.com/smudge/nightlight/issues/22`)awaitterminal(`brew install smudge/smudge/nightlight`)awaitarg("Press enter when installing in terminal finishes...")console.clear()// Clear previous console.logreturnmain()})letstatus=execaSync('nightlight',['status']).stdoutlettemp=execaSync('nightlight',['temp']).stdoutletchoices: Choice[]=[{name: 'Toggle',value: 'toggle'},{name: 'Off',value: 'off'},{name: 'On',value: 'on'},{name: 'On & 25%',value: 'temp 25'},{name: 'On & 50%',value: 'temp 50'},{name: 'On & 75%',value: 'temp 75'},{name: 'On & 100%',value: 'temp 100'}]letchoice=awaitarg({placeholder: `Either select or type exact amount from 0 to 100`,hint: `Current status: ${uppercaseFirst(status)} • Current temperature: ${temp}`,
choices,strict: false// allow arbitrary input})letargs=choice.split(' ')letisArg0Number=!isNaN(parseInt(args[0]))if(isArg0Number){args=['temp',args[0]]}if(args[0]==='temp'){// if setting temp, turn on firstawaitexeca('nightlight',['on'])}awaitexeca('nightlight',args).then(()=>notify(`Nightlight set to: ${choice}`)).catch(()=>notify(`Failed to set Nightlight to: ${choice}`))}voidmain()functionuppercaseFirst(str: string){returnstr.charAt(0).toUpperCase()+str.slice(1)}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Screenshot-2024-11-30T14.28.44.mp4
Open macos-night-shift in Script Kit
Beta Was this translation helpful? Give feedback.
All reactions