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
Leon André Bergman
60 discussion posts
Hi. I'm looking for a way to make my macros a bit smarter.
I would like to make a macro copy a text from a field in a form (I already have this set up) and use this text to decide what macro to run.

So say I copy text A, the macro will run the next macro named A.
If the text is B, then it will run Macro B, and so on.

Is this possible?
Aug 15, 2019  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Sure! There are a couple of ways you could do this. You could create Trigger rules that look for the specific text and then run the appropriate Macro.

Alternatively, you could do it in a Macro, like this:

Code

if (text == "A")
        {
            BFS.ClipboardFusion.RunMacro("Macro1", text, out text);
        }
        else if (text == "B")
        {
            BFS.ClipboardFusion.RunMacro("Macro2", text, out text);
        }
        return text;
Aug 15, 2019 (modified Aug 15, 2019)  • #2
User Image
Leon André Bergman
60 discussion posts
I'm sorry for the late reply. That seems to work perfectly. Thank you very much.
Aug 21, 2019  • #3
Keith Lammers (BFS)'s profile on WallpaperFusion.com
No worries, glad to hear it!
Aug 21, 2019  • #4
User Image
Leon André Bergman
60 discussion posts
I've finaly had time to try and implement this into my workflow, but it's not actually working now.

I've set it up like this.

Code

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        // your code goes here
    BFS.Input.SetMousePosition(-1502, 518);
    BFS.General.ThreadWait(500);
    BFS.Input.LeftClickMouse();
    BFS.General.ThreadWait(500);
    BFS.Input.SendKeys("^({VK_65})");
    BFS.General.ThreadWait(500);
    BFS.Clipboard.CopyText();
    BFS.General.ThreadWait(500);
        // your code goes here
        if (text == "ping")
        {
            BFS.ClipboardFusion.RunMacro("#8 Fra Search: Sett til Pending #OVE 3 days", text, out text);
        }
        else if (text == "B")
        {
            BFS.ClipboardFusion.RunMacro("Macro2", text, out text);
        }
    
    return text;
    }
}


It is able to move the mouse to the correct position, mark the text, and copy it(i assume), but it's not running the macro, even though the copied text contains "ping"
It's not doing anything. It just ends without any errors.
Aug 30, 2019  • #5
Thomas Malloch (BFS)'s profile on WallpaperFusion.com
I put together something that should work for you. All I did was modify your code a little.

The reason your Macro wasn't working is because when a Macro is run, the "text" variable contains the text that was in the Clipboard at the time when the Macro first runs. It doesn't change again automatically, unless you change it yourself :).

So the only real change I made to your Macro was on line 12. I change the

Code

BFS.Clipboard.CopyText();

to

Code

text = BFS.Clipboard.CopyText();


Anyways, here's the code!

Code

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        BFS.Input.SetMousePosition(-1502, 518);
        BFS.General.ThreadWait(500);
        BFS.Input.LeftClickMouse();
        BFS.General.ThreadWait(500);
        BFS.Input.SendKeys("^({VK_65})");
        BFS.General.ThreadWait(500);
        
        // set the "text" variable with the contents of the Clipboard
        text = BFS.Clipboard.CopyText();
        BFS.General.ThreadWait(500);
        
        if (text == "ping")
        {
            BFS.ClipboardFusion.RunMacro("#8 Fra Search: Sett til Pending #OVE 3 days", text, out text);
        }
        else if (text == "B")
        {
            BFS.ClipboardFusion.RunMacro("Macro2", text, out text);
        }
    
        return text;
    }
}
Sep 3, 2019  • #6
User Image
Leon André Bergman
60 discussion posts
Oh. I see. That makes sense then. I'll try this one out. Thank you.
Sep 30, 2019  • #7
User Image
Leon André Bergman
60 discussion posts
Yep. That seems to work. But I've just realized I need to actually check for if text contains, not if it equals. I guess I can add a scrubbing of the text it copies, but is there maybe an easier way of implementing into the if statement?
Sep 30, 2019  • #8
Keith Lammers (BFS)'s profile on WallpaperFusion.com
You can change it from:
if (text == "ping")


to:
if (text.Contains("ping"))


Hope that helps!
Oct 1, 2019  • #9
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)