Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Sleepy


  • Please log in to reply
2 replies to this topic
Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Sleepy is an automation script that reduces the master volume over a period of time. After the period of time has elapsed, it can shutdown your computer, or put it into suspend mode, or do nothing. It can also wake you up again by fading up the master volume over a given amount of time. These options can be set in the gui below:

Posted Image

The tray icon reflects the position of the volume control and it's tooltip contains the position of the fader. The user can also open the Volume Control window via the tray menu. I used an icon file and part of the Volume in tray script by PerezDeQueya80.

You can download the script and icons here.

; Sleepy v2.2 by Serenity

#singleinstance force
menu, tray, useerrorlevel
menu, tray, click, 1

menu, tray, nostandard

menu, tray, add, &Show Settings, show
menu, tray, default, &Show Settings
menu, tray, add, Show &Volume Control, showvol
menu, tray, add, &About..., about
menu, tray, add
menu, tray, add, E&xit, exit

setworkingdir %A_ScriptDir%
title = Sleepy
version = v2.2

gosub, icon

gui, -minimizebox
gui, font, S8, tahoma

gui, add, groupbox, x16 y17 w310 h70, Fade out duration
gui, add, picture, x30 y40 h32 w32, speaker.ico
gui, add, text, x76 y47 w170 h20, Enter the fade out time in minutes:
gui, add, edit, x246 y44 w50 h20 vfadetime, 30

gui, add, groupbox, x16 y107 w310 h160, Action to take when fade out has elapsed
gui, add, picture, x30 y130 h32 w32, computer.ico
gui, add, radio, checked x76 y137 w220 h20 vnothing, Do nothing
gui, add, radio, x76 y167 w220 h20 vshutdown, Shutdown computer and power off
gui, add, radio, x76 y197 w240 h20 vsuspend, Put computer into Suspend mode
gui, add, radio, x76 y227 w240 h20 vwakeup, Wake up (set wake up time below)

gui, add, groupbox, x16 y287 w310 h70, Wake up duration
gui, add, picture, x30 y310 w32 h32, speaker.ico
gui, add, text, x76 y317 w170 h20, Enter the wake up time in minutes:
gui, add, edit, x246 y314 w50 h20 vwaketime

gui, add, button, default x116 y377 w110 h30 gstart, Start Sleepy

gui, show, h428 w345, %title%

settimer, icon, 500 ; keep the tray icon and tooltip updated
return



start:
gui, +owndialogs
gui, submit

if fadetime = ; the user didn't enter a value
{
  msgbox, 64, %title%, A fade out time was not entered.
  gui, show, h428 w345, %title%
  return
}

if (wakeup = 1 and waketime = "") ; the user didn't enter a value
{
  msgbox, 64, %title%, A wake up time was not entered.
  gui, show, h428 w345, %title%
  return
}

soundget, vol
soundget, startvol
fadeouttime := (((fadetime * 60000) / vol) / 10)
settimer, volume, %fadeouttime%
return


volume:
soundget, vol
soundset, -0.1
if vol = 0
{
  settimer, volume, off
  sleep, %fadeouttime%
  soundset, 1, , mute ; mute

  if nothing = 1
    return
  if shutdown = 1
    gosub, shutdown
  if suspend = 1
    gosub, suspend
  if wakeup = 1
    gosub, wakeup
}
else
  gosub, icontip
return


show:
gui, show, h428 w345, %title%
return


shutdown:
shutdown, 9 ; shutdown and power off
exitapp
return


suspend:
DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
return


wakeup:
wakeuptime := (((waketime * 60000) / startvol) / 10)
settimer, wake, %wakeuptime%
return


wake:
soundset, 0, , mute ; unmute
soundget, vol
soundset, +0.1
if (vol = startvol)
{
  settimer, wake, off
  return
}
else
  gosub, icontip
return


icon:
soundget, vol

icontip:
volico := ((vol * 0.15) + 2)
menu, tray, icon, volicos.icl, %volico%

; display the volume in a tooltip:
setformat, float, 0
voltip := (vol + 0)
menu, tray, tip, %title% - %voltip%`%
return


showvol:
process, exist, SNDVOL32.EXE
if errorlevel = 0
{
  run, %A_WinDir%\SYSTEM32\SNDVOL32.EXE, useerrorlevel
}
else
  winactivate, ahk_class Volume Control
return


about:
msgbox, , About..., Sleepy %version%`nCopyright (c) 2006 Serenity`n`nhttp://serenity.pixelarmy.org/
return


exit:
exitapp

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

toralf
  • Moderators
  • 4035 posts
  • Last active: Aug 20 2014 04:23 PM
  • Joined: 31 Jan 2005
I like the interface and the use of the icons. Very nice.

I would suggest to put this code
soundget, vol 
volico := ((vol * 0.15) + 2) 
menu, tray, icon, volicos.icl, %volico% 

; display the volume in a tooltip: 
setformat, float, 0 
voltip := (vol + 0) 
menu, tray, tip, %title% - %voltip%`% 
into a subroutine and call it everytime you use it.

volume and wake do nearly the same thing, one is increasing the volume the other is decreasing. Maybe you can make a function from it, that does both (one or the other, depending on a parameter) That might save code as well and help maintainance.
Ciao
toralf
 
I use the latest AHK version (1.1.15+)
Please ask questions in forum on ahkscript.org. Why?
For online reference please use these Docs.

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Thanks toralf. :) I shortened the script quite a bit with your suggestion.

Other changes (v2.2) - I noticed that I could still hear audio very faintly with the master volume at 0, so I updated the script to mute the master volume when volume has reached 0.
"Anything worth doing is worth doing slowly." - Mae West
Posted Image