Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

User Image
AlanBes
29 discussion posts
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 window (chrome) is the focused app will be appreciated.

Code

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;
    }
}


Just spotted this went into the DisplayFusion section - apologies for that!
May 6, 2019 (modified May 6, 2019)  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Something like this should work:

Code

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;
}


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.
May 7, 2019 (modified May 7, 2019)  • #2
User Image
AlanBes
29 discussion posts
Thank you replying. That's much neater than my solution.
May 7, 2019  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
No worries, glad I could help!
May 8, 2019  • #4
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)