<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>DisplayFusion RSS: Running macro only if app has focus</title>
<atom:link href="https://www.displayfusion.com/Discussions/RSS/?TopicID=0e02ed88-5529-445c-a809-7e63cbb43e95" rel="self" type="application/rss+xml" />
<link>https://www.displayfusion.com/Discussions/RSS/?TopicID=0e02ed88-5529-445c-a809-7e63cbb43e95</link>
<description>DisplayFusion RSS: Running macro only if app has focus</description>
<lastBuildDate>Sat, 20 Jun 2026 09:26:41 GMT</lastBuildDate>
<language>en</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>https://www.displayfusion.com/Discussions/RSS/?TopicID=0e02ed88-5529-445c-a809-7e63cbb43e95</generator>
<item>
<title>RE: Running macro only if app has focus</title>
<link>https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95#4</link>
<pubDate>Wed, 08 May 2019 15:48:57 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95#4</guid>
<category>DisplayFusion</category>
<description><![CDATA[No worries, glad I could help!]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
No worries, glad I could help!
</div>
]]></content:encoded>
</item>
<item>
<title>RE: Running macro only if app has focus</title>
<link>https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95#3</link>
<pubDate>Tue, 07 May 2019 18:56:05 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95#3</guid>
<category>DisplayFusion</category>
<description><![CDATA[Thank you replying. That's much neater than my solution.]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
Thank you replying. That's much neater than my solution.
</div>
]]></content:encoded>
</item>
<item>
<title>RE: Running macro only if app has focus</title>
<link>https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95#2</link>
<pubDate>Tue, 07 May 2019 18:54:00 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95#2</guid>
<category>DisplayFusion</category>
<description><![CDATA[Something like this should work:
Code
Copy
Select All
using System;
using System.Text.RegularExpressions;
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
if (BFS.Window.GetText(BFS.Window.GetFocusedWindow()).Contains("Chrome"))
{
BFS.Dialog....]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
Something like this should work:<br/>
<div class="col-md-12 BoxWrap"><div class="Box table-responsive"><a name="code" style="width:0; height:0;"></a><h2 class="TableTitle" style="border:0"><div class="TableTitleText">Code</div><div class="TitleButtons"><div class="TableTitleButton"><a href="#" onclick="return false;" data-clipboard-target="#code019ee45a92ef741c92e90b44958ee07d" class="ClipboardCopyControl"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/clone.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;width:auto;max-width:16px;height:16px;" /><span class="Text">Copy</span></a></div><div class="TableTitleButton"><a href="#" onclick="bfs.util.codeEditorSelectAll('code019ee45a92ef741c92e90b44958ee07dJs'); return false;"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/square-check.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;width:auto;max-width:16px;height:16px;" /><span class="Text">Select All</span></a></div></div></h2><div class="TableTitleContent table-responsive"><div class="AceEditorWrapper" style="border-top:solid 1px var(--color-default-border);padding:0"><pre id="code019ee45a92ef741c92e90b44958ee07dJs" contenteditable="true" spellcheck="true" class="skiptranslate" style="width:100%; min-height:75px;">using System;
using System.Text.RegularExpressions;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        if (BFS.Window.GetText(BFS.Window.GetFocusedWindow()).Contains("Chrome"))
        {
            BFS.Dialog.ShowMessageInfo("blah");
            
            //use the Regex class to replace any matched text with an empty string
            if (text.Contains("**"))
            {
            text = text.Replace ("**","");
            text = Regex.Replace (text, @"(.*),.*- (.*),.*(\(.*)", "$1 vs $2 $3");
            }    
            else
            {
                text = Regex.Replace (text, @"\n", "");
                text = Regex.Replace (text, @".*\[Date ""([1-2][0-9][0-9][0-9]).*\[White ""(.*)"".*\[Black ""(.*)"".*\[Result.*", "**$2 - $3** ($1)");
            }
                
                BFS.Clipboard.PasteText(text);
                //get ClipboardFusion to replace the text on the clipboard with the text variable
            }
        }
        return text;
}</pre><textarea id="code019ee45a92ef741c92e90b44958ee07d" name="code019ee45a92ef741c92e90b44958ee07d" style="position:absolute; top:0; left:-999999px; width:1px; height:1px;"></textarea></div>
</div></div></div><br/>
<br/>
Note that the "return text;" line needs to either be outside of the if statement, or you have to include it in all of the if/else blocks. (all possible code paths have to return a string). You can also do "return null;" instead if you don't want to put anything back on the clipboard.
</div>
]]></content:encoded>
</item>
<item>
<title>Running macro only if app has focus</title>
<link>https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95</link>
<pubDate>Mon, 06 May 2019 20:14:30 GMT</pubDate>
<dc:creator>Binary Fortress Software</dc:creator>
<guid isPermaLink="false">https://www.displayfusion.com/Discussions/View/running-macro-only-if-app-has-focus/?ID=0e02ed88-5529-445c-a809-7e63cbb43e95</guid>
<category>DisplayFusion</category>
<description><![CDATA[Simple script in ClipboardFusion to replace text.
But I need the macro to only run if Chrome is the focused application.
Had a look at GetMainFileByWindow and other functions but can't get them implemented into the code.
Here's a sample of the current code, and help to add a statement if a win...]]></description>
<content:encoded><![CDATA[<div class="CTDiscussions">
Simple script in ClipboardFusion to replace text.<br/>
But I need the macro to only run if Chrome is the focused application.<br/>
Had a look at GetMainFileByWindow and other functions but can't get them implemented into the code.<br/>
Here's a sample of the current code, and help to add a statement if a window (chrome) is the focused app will be appreciated. <br/>
<div class="col-md-12 BoxWrap"><div class="Box table-responsive"><a name="code" style="width:0; height:0;"></a><h2 class="TableTitle" style="border:0"><div class="TableTitleText">Code</div><div class="TitleButtons"><div class="TableTitleButton"><a href="#" onclick="return false;" data-clipboard-target="#code019ee45a92f777ecbb9cc7ffd150afe8" class="ClipboardCopyControl"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/clone.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;width:auto;max-width:16px;height:16px;" /><span class="Text">Copy</span></a></div><div class="TableTitleButton"><a href="#" onclick="bfs.util.codeEditorSelectAll('code019ee45a92f777ecbb9cc7ffd150afe8Js'); return false;"><img src="https://www.displayfusion.com/MediaCommon/SVGs/FontAwesome/square-check.blue.svg" style="box-sizing:border-box;position:relative;overflow:hidden;width:auto;max-width:16px;height:16px;" /><span class="Text">Select All</span></a></div></div></h2><div class="TableTitleContent table-responsive"><div class="AceEditorWrapper" style="border-top:solid 1px var(--color-default-border);padding:0"><pre id="code019ee45a92f777ecbb9cc7ffd150afe8Js" contenteditable="true" spellcheck="true" class="skiptranslate" style="width:100%; min-height:75px;">using System;
using System.Text.RegularExpressions;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        //use the Regex class to replace any matched text with an empty string
    if (text.Contains("**"))
    {
    text = text.Replace ("**","");
    text = Regex.Replace (text, @"(.*),.*- (.*),.*(\(.*)", "$1 vs $2 $3");
    }    
    else
    {
        text = Regex.Replace (text, @"\n", "");
        text = Regex.Replace (text, @".*\[Date ""([1-2][0-9][0-9][0-9]).*\[White ""(.*)"".*\[Black ""(.*)"".*\[Result.*", "**$2 - $3** ($1)");
    }
        
        BFS.Clipboard.PasteText(text);
        //get ClipboardFusion to replace the text on the clipboard with the text variable
        return text;
    }
}</pre><textarea id="code019ee45a92f777ecbb9cc7ffd150afe8" name="code019ee45a92f777ecbb9cc7ffd150afe8" style="position:absolute; top:0; left:-999999px; width:1px; height:1px;"></textarea></div>
</div></div></div><br/>
<br/>
Just spotted this went into the DisplayFusion section - apologies for that!
</div>
]]></content:encoded>
</item>
</channel>
</rss>