ezuk
Joined: 04 Jun 2005 Posts: 122
|
Posted: Wed May 14, 2008 9:47 am Post subject: WorkRave Helper |
|
|
WorkRave is a program that helps you take breaks from work, to prevent RSI and exhaustion.
It allows for "micro-breaks" (30 seconds or so, configurable) and "rest breaks" (longer breaks, 5-10 minutes, in which you're supposed to get up and move).
It has a setting to count "micro breaks" as activity (i.e, reduce them from the total duration of your "daily limit" timer -- your daily timer keeps ticking while you're taking a micro-break).
It has no such setting for rest breaks. I.e, if you take a rest break, the daily timer just stops (thus extending your workday just because you took a short breather, which is acceptable during a workday).
This script hacks WorkRave to add this functionality. It's a very ugly hack, but it's the only way I found which works. It counts the time the Rest Break window is shown on-screen, and then changes the Daily Limit value in the registry to reflect that (and thus deduct that time from the remaining time of your workday).
Since WorkRave is a cross-platform application originally coded for Linux, it uses a non-native GUI toolkit (GTK, I believe). Thus, functions such as ControlClick or SendMessage did _not_ work, no matter how hard I tried. I ended up manipulating the windows with plain old mouse clicks.
Any suggestions for improvement would be appreciated. Especially if you can make this thing work without mouse clicks (or registry hacks...).
| Code: |
if not A_IsAdmin
{
DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
, str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1) ; Last parameter: SW_SHOWNORMAL = 1
ExitApp
}
SetTitleMatchMode, 1
Loop {
BreakDuration = 0
WinWait,Rest break
SetTimer,BreakDuration,1000
WinWaitClose, Rest break
SetTimer,BreakDuration,Off
Gosub,DeductDuration
}
return
BreakDuration:
BreakDuration++
return
DeductDuration:
RegRead,CurrentLimit,HKCU,Software\Workrave\timers\daily_limit,limit
NewLimit := CurrentLimit-BreakDuration
RegWrite,REG_SZ,HKCU,Software\Workrave\timers\daily_limit,limit,%NewLimit%
GoSub, RefreshGuiCounters
return
RefreshGuiCounters:
BlockInput,SendAndMouse
CoordMode,Mouse,Screen
MouseGetPos,SavedMouseX,SavedMouseY
CoordMode,Mouse,Relative
IfWinNotExist,ahk_class gdkWindowToplevel,Gosub WaitForSmallWindow
WinShow,ahk_class gdkWindowToplevel
WinActivate,ahk_class gdkWindowToplevel
MouseClick,right,50,35,1,0
send,p
WinWait,Preferences
MouseClick,left,364,56,1,0
MouseClick,left,373,140,2,0
Send,{Down}{Up}
WinClose
WinHide,ahk_class gdkWindowToplevel
CoordMode,Mouse,Screen
MouseMove,%SavedMouseX%,%SavedMouseY%,0
CoordMode,Mouse,Relative
return
WaitForSmallWindow:
Msgbox Please display Workrave's mini-applet by clicking on the WorkRave tray icon.
WinWait,ahk_class gdkWindowToplevel
return
|
|
|