Schedule onidle tasks from Tcl

Most of my errors with an ONIDLE scheduled task were from incomplete paths. I needed to supply the absolute path to the executable because the task would run in the system context, not any local directory.

set exe_path [file normalize [file join [file dirname \
  [info script] run-task.exe]]]

exec schtasks /tn task001 /tr $exe_path /sc onidle /I 1

exit 0

Tcl, above any other language, has made me focus on paths. That first line in its various combinations will likely be in every one of my future scripts.

You can test ONIDLE scheduled tasks immediately with

schtasks /run /tn task001

The diagram at the URL below really expanded my mind about timelines: