{"id":792,"date":"2019-05-29T09:18:10","date_gmt":"2019-05-29T09:18:10","guid":{"rendered":"https:\/\/ptfbpro.com\/automate\/?p=792"},"modified":"2019-05-29T09:18:25","modified_gmt":"2019-05-29T09:18:25","slug":"how-to-run-a-macro-whenever-a-window-becomes-active","status":"publish","type":"post","link":"https:\/\/ptfbpro.com\/automate\/how-to-run-a-macro-whenever-a-window-becomes-active\/","title":{"rendered":"How to run a macro whenever a window becomes active"},"content":{"rendered":"<p>Recently I was asked if there&#8217;s a way to get PTFB Pro to run a macro (or a single press item) whenever the target window becomes active. This can indeed be done using a little oft-ignored setting on the &#8220;Identifying the Target&#8221; page of the macro&#8217;s properties:<\/p>\n<p><a href=\"https:\/\/ptfbpro.com\/automate\/wp-content\/uploads\/2019\/05\/FireIfForeground.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-793\" src=\"https:\/\/ptfbpro.com\/automate\/wp-content\/uploads\/2019\/05\/FireIfForeground.png\" alt=\"Fire only if foreground\" width=\"570\" height=\"531\" srcset=\"https:\/\/ptfbpro.com\/automate\/wp-content\/uploads\/2019\/05\/FireIfForeground.png 570w, https:\/\/ptfbpro.com\/automate\/wp-content\/uploads\/2019\/05\/FireIfForeground-300x279.png 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/a><\/p>\n<p>The key is to tick the &#8220;Fire only if foreground window&#8221; option; with this set, the macro will only run automatically if the target window is active, ie. the foreground window. Whenever the window becomes inactive (because you&#8217;re working in another window) it will fall off PTFB&#8217;s radar, but when the window becomes active again PTFB will see it and launch the macro according to the other settings you&#8217;ve made on the &#8220;Triggers&#8221; page.<\/p>\n<p>In the above example you can see I&#8217;m using this technique with a Window Restore macro for the Opera browser; I have it set to correctly maximize Opera whenever it becomes the foreground app. There are a few other things to note about this example. Firstly, like other browsers Opera changes its window title according to the web page currently being viewed; to make my macro match Opera <em>regardless<\/em> of the page I&#8217;m viewing, I&#8217;ve set it to match any window whose title ends with &#8221; &#8211; Opera&#8221;. I&#8217;ve also specified that only windows that are owned by the Opera process (&#8220;opera .exe&#8221;) are to be considered a match &#8211; this latter setting makes it easier and faster for PTFB Pro to identify genuine Opera windows.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I was asked if there&#8217;s a way to get PTFB Pro to run a macro (or a single press item) whenever the target window becomes active. This can indeed <a class=\"more-link\" href=\"https:\/\/ptfbpro.com\/automate\/how-to-run-a-macro-whenever-a-window-becomes-active\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-792","post","type-post","status-publish","format-standard","hentry","category-news"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/posts\/792"}],"collection":[{"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/comments?post=792"}],"version-history":[{"count":3,"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/posts\/792\/revisions"}],"predecessor-version":[{"id":796,"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/posts\/792\/revisions\/796"}],"wp:attachment":[{"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/media?parent=792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/categories?post=792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ptfbpro.com\/automate\/wp-json\/wp\/v2\/tags?post=792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}