{"id":2031,"date":"2020-08-17T23:01:52","date_gmt":"2020-08-18T03:01:52","guid":{"rendered":"https:\/\/mberlove.com\/blog\/?p=2031"},"modified":"2023-01-29T23:49:34","modified_gmt":"2023-01-30T04:49:34","slug":"solution-space-unexpected-shutdown","status":"publish","type":"post","link":"https:\/\/mberlove.com\/blog\/solution-space-unexpected-shutdown\/","title":{"rendered":"Solution Space: Unexpected Shutdown"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"bf gx gy c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/max\/700\/0*C4_wi-tYDGmkdPrL.png\" alt=\"\" width=\"700\" height=\"394\" \/><\/p>\n<p id=\"dcc6\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">You\u2019re in the middle of finishing up an important document, using reference materials scattered across browser tabs, open PDFs, and an email chain \u2014 and your computer shuts down.<\/p>\n<p id=\"069e\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Whether due to system error or a scheduled mandatory upgrade, unexpected shutdowns represent an exorbitant pain for any user \u2014 doubly for so-called \u201cpower users\u201d who tend to have dozens of windows and consoles open simultaneously. Losing that context on shutdown can throw you off your game, and cost significant time to get back on track.<\/p>\n<p id=\"e2ee\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Managing this issue differs by system; for instance, macs have a decent feature for reopening windows and programs after a shutdown. What about Windows users? Windows does include a feature to <a class=\"ae iw\" href=\"https:\/\/www.tenforums.com\/tutorials\/67701-turn-restore-previous-folder-windows-logon-windows-10-a.html\" target=\"_blank\" rel=\"noopener ugc nofollow\">resume open programs<\/a> on startup, but it\u2019s buggy, inconsistent, and often won\u2019t resume unsaved items the way mac does (even on mac, to be fair, the feature is not perfect).<\/p>\n<p id=\"8637\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">For me, leveraging a windows\/linux dual boot, it\u2019s a big deal. I often switch back and forth between each OS, which requires a shutdown (hibernate is an option \u2014 but doesn\u2019t always work cleanly).<\/p>\n<p id=\"e7d4\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">After one nuisance of a Blue Screen of Death during the middle of a recording session, I decided to solve this problem for myself.<\/p>\n<p style=\"text-align: center;\" data-selectable-paragraph=\"\">* * *<\/p>\n<p class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">As I sat down to think about how to fix this, I realized it can\u2019t be one of my bigger projects. A relatively rare problem, it\u2019s not worth it to spend long hours coding a custom solution to tie into the Windows APIs and work 100% perfectly to all my needs.<\/p>\n<p id=\"af4a\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">What I want is something simple \u2014 a list of open windows, so that if my open programs fail to resume after a shutdown, I can read off a list of previously open windows and identify what is missing. A matter of moments.<\/p>\n<p id=\"d117\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">But how to get there? The key factors are as follows:<\/p>\n<p id=\"c6ce\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">1 ) <strong class=\"ia hc\">Easy to build<\/strong>. I don\u2019t want to spend hours coding. This means either applying an existing solution, or using a point-and-click interface.<\/p>\n<p id=\"173e\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">2 ) <strong class=\"ia hc\">Windows compatibility<\/strong>. Windows has its own APIs for window management, whereas a more universal solution might not work consistently.<\/p>\n<p id=\"f547\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">3 ) <strong class=\"ia hc\">Readable output<\/strong>. I opt to forgo a more complex solution to actually reopen my programs, which in any case might conflict with Window\u2019s own feature to do this. Instead, I just want a list \u2014 but that list should be pretty clear so I can see what I\u2019m missing.<\/p>\n<p id=\"091d\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">What tool or framework meets the criteria noted above?<\/p>\n<p id=\"7c7b\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">It\u2019s time to dig out a name I hadn\u2019t thought about in years: <a class=\"ae iw\" href=\"https:\/\/www.autoitscript.com\" target=\"_blank\" rel=\"noopener ugc nofollow\"><strong class=\"ia hc\">AutoIt<\/strong><\/a>.<\/p>\n<p id=\"978f\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Rather than trying to describe it myself, I\u2019ll let AutoIt\u2019s site do the talking:<\/p>\n<blockquote>\n<p data-selectable-paragraph=\"\">AutoIt v3 is \u2026 designed for automating the Windows GUI and general scripting \u2026 to automate tasks in a way not possible or reliable with other languages.<\/p>\n<\/blockquote>\n<p id=\"5ed0\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Most pertinently, AutoIt is simple, works out-of-the-box, and has lots of Windows API tie-ins that make scripting a breeze. It\u2019s not common that I run across an aspect of my daily workflow that requires this kind of automation, so it\u2019s been a while since I\u2019ve used it! But it\u2019s such a simple setup that in literally two minutes, I\u2019ve got it up and running again.<\/p>\n<p id=\"e284\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Before I can be sure that AutoIt will fit my needs, it\u2019s important to check how hard it will be to get a list of open windows\u2026<\/p>\n<p data-selectable-paragraph=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"bf gx gy c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/max\/700\/1*D38WLquO-eO-CiRXAF_Rig.png\" alt=\"\" width=\"700\" height=\"500\" \/><\/p>\n<p id=\"5a5d\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">\u2026fortunately, <a class=\"ae iw\" href=\"https:\/\/stackoverflow.com\/questions\/18456091\/get-a-list-of-all-open-windows-using-autoit\" target=\"_blank\" rel=\"noopener ugc nofollow\">StackOverflow<\/a>, via a quick Google search, has done the hard work for me.<\/p>\n<p id=\"0cfd\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">I try this script out in AutoIt and find that it works. However, it outputs to console, and I need a written list that I can reference. Jumping into the AutoIt documentation, a quick text search in the function reference leads me to a way to <a class=\"ae iw\" href=\"https:\/\/www.autoitscript.com\/autoit3\/docs\/functions\/FileWriteLine.htm\" target=\"_blank\" rel=\"noopener ugc nofollow\">write to a file<\/a>, including a handy example.<\/p>\n<p id=\"b583\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">It\u2019s a matter of moments to rewrite my script to output to a file using the new example rather than writing to console. I test the script, and it works! I have a document containing a list of all open windows \u2014 just what I want.<\/p>\n<p id=\"43bc\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Now I\u2019m 90% of the way to a solution, but I\u2019m missing one crucial element: the script needs to be run manually, which doesn\u2019t help me if the computer shuts itself down while I\u2019m not looking.<\/p>\n<p id=\"be3b\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">Fortunately, Windows has a way to schedule processes to run automatically via the <a class=\"ae iw\" href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/taskschd\/using-the-task-scheduler\" target=\"_blank\" rel=\"noopener ugc nofollow\">task scheduler<\/a>.<\/p>\n<p data-selectable-paragraph=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"bf gx gy c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/max\/626\/1*VOX8PpiRXrVOBZpPCeuiOQ.png\" alt=\"\" width=\"626\" height=\"472\" \/><\/p>\n<p data-selectable-paragraph=\"\">I set up a new task which repeats every hour on the hour \u2014 you could change this to a different period of time depending on your needs; for me, an hour is about right. Now it just needs something to run. I could have it run the AutoIt script runner and take the script as a parameter, but there\u2019s a cleaner way: AutoIt provides a utility to turn a script into an executable program!<\/p>\n<p data-selectable-paragraph=\"\"><img loading=\"lazy\" decoding=\"async\" class=\"bf gx gy c\" role=\"presentation\" src=\"https:\/\/miro.medium.com\/max\/594\/1*E-GdkzPH8TLCkTovOz2PMQ.png\" alt=\"\" width=\"594\" height=\"417\" \/><\/p>\n<p id=\"08ce\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">In a matter of moments, I have an executable file that I can set as the action of my new task in the task scheduler.<\/p>\n<p id=\"dad2\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\"><strong class=\"ia hc\">And we\u2019re done!<\/strong> In something like ten minutes, I went from identifying a nagging problem, through some very basic analysis, to generating a solution. It\u2019s small, it\u2019s easy, it\u2019s not at all demanding on my system\u2019s resources, and now I won\u2019t have to worry about losing control of my open workflow.<\/p>\n<h1 id=\"fdde\" class=\"js jt hb bd ju jv jw jx jy jz ka kb kc kd ke kf kg kh ki kj kk kl km kn ko kp bi\" data-selectable-paragraph=\"\">Potential Improvements<\/h1>\n<ul>\n<li>As you might notice if you followed along in practice, the list of windows that gets written to the document includes all the open background tasks, and many redundancies, so that the end list can prove difficult to peruse, and makes for unsightly reading, cluttered with unnecessary information. Paring this down, either via AutoIt\u2019s WinList or an external means like a regex via PowerShell, would lead to a more effective solution.<\/li>\n<li>I find my list of open windows really useful, but it would be much <em class=\"jh\">more <\/em>useful to have them open by themselves. AutoIt could almost certainly handle this, but for me, it wasn\u2019t quite worth the effort. By turning off Window\u2019s automatic restoring feature, you could avoid any conflicts, and use only your own solution to restore your workflow.<\/li>\n<li>Because a new document is generated every hour, the list will quickly grow and grow. I currently have the documents output to their own subfolder, and they\u2019re fairly small so I don\u2019t need to worry about space constraints, but it would be nice to have a rolling \u201ccleanup\u201d that gets rid of any documents older than, say, thirty days.<\/li>\n<\/ul>\n<h1 id=\"163d\" class=\"js jt hb bd ju jv jw jx jy jz ka kb kc kd ke kf kg kh ki kj kk kl km kn ko kp bi\" data-selectable-paragraph=\"\">Discussion<\/h1>\n<p id=\"3ebb\" class=\"pw-post-body-paragraph hy hz hb ia b ib ks id ie if kt ih ii ij lg il im in lh ip iq ir li it iu iv gj bi\" data-selectable-paragraph=\"\">As problems go, this was a minor one. As solutions go, I got lucky that such a simple answer could be pulled together. But large or small, the key aspects of solving any such problem generally fall into three categories:<\/p>\n<p id=\"100b\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">1) <strong class=\"ia hc\">Identifying the key problem<\/strong>, and the scope. For me, this meant trading off time for a simpler solution, and realizing what would meet my needs.<\/p>\n<p id=\"3382\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">2) <strong class=\"ia hc\">Awareness of the solution space<\/strong>. There are many ways to solve a problem, but for me, for this issue, AutoIt was the way to go. If I hadn\u2019t known about AutoIt, I might have had a harder time coming up with a solution. However, you can usually preempt such trouble, by\u2014<\/p>\n<p id=\"7f07\" class=\"pw-post-body-paragraph hy hz hb ia b ib ic id ie if ig ih ii ij ik il im in io ip iq ir is it iu iv gj bi\" data-selectable-paragraph=\"\">3) <strong class=\"ia hc\">Gathering information efficiently<\/strong>. Once on the trail of the solution, being able to find enough information to build a picture of how to solve the problem is a critical skill, and one that can definitely be developed. In this day and age, Google and other tools often make it child\u2019s play to come up with a mountain of relevant information, such that it\u2019s more important to be able to filter <em class=\"jh\">out<\/em> bad information than to <em class=\"jh\">locate <\/em>good information. But either way, and no matter the means by which you compile the information, thinking critically about what information will lead you on the right path without restricting your vision too narrowly is how you navigate efficiently to a solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You\u2019re in the middle of finishing up an important document, using reference materials scattered across browser tabs, open PDFs, and an email chain \u2014 and your computer shuts down. Whether due to system error or a scheduled mandatory upgrade, unexpected [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[218],"tags":[221,220,219],"class_list":["post-2031","post","type-post","status-publish","format-standard","hentry","category-solution-space","tag-analysis","tag-automation","tag-workflow"],"_links":{"self":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts\/2031","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/comments?post=2031"}],"version-history":[{"count":4,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts\/2031\/revisions"}],"predecessor-version":[{"id":2051,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/posts\/2031\/revisions\/2051"}],"wp:attachment":[{"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/media?parent=2031"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/categories?post=2031"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mberlove.com\/blog\/wp-json\/wp\/v2\/tags?post=2031"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}