Making Malwarebytes Anti-Malware Scan Automatically on Your Mac

Make Malwarebytes Anti-Malware Scan Automatically

Author’s Note: I’ve edited this article. It appears WordPress changed some quotation marks into “curly” quotation marks in the code. Sorry if you tried it and it failed; it should work now!

I set out to create a way to make Malwarebytes Anti-Malware scan automatically. It’s vital to run a malware detection and removal app on your Mac, and while Malwarebytes Anti-Malware is one of my favorites, it doesn’t scan automatically. This became blatantly obvious recently when Handbrake was infected with malware. The problem is, most people don’t need to run such a scan daily, and we forget if it’s not part of our day-to-day routine. With that in mind, let me show you how I made Malwarebytes Anti-Malware scan automatically.

Make Malwarebytes Anti-Malware Scan Automatically
Don’t let this guy get the best of you when you can make Malwarebytes Anti-Malware scan automatically (Image Credit: HypnoArt)

What Apps Do I Need?

To make Malwarebytes Anti-Malware scan automatically, we need a couple of apps. First, of course, is Malwarebytes Anti-Malware itself—it’s free. Second, you should download and install Keyboard Maestro. It’s a paid app, but you can try it for free and make sure it does what you need it to. Honestly, once you start using Keyboard Maestro, you might be glad I introduced you to it—and Dr. Mac can’t say enough good things about it. In addition to everything else it does, Keyboard Maestro has a clipboard manager that’s second to none.

Making Malwarebytes Anti-Malware Scan Automatically

The first thing we need is a way to automatically launch Malwarebytes Anti-Malware for macOS Sierra and tell it to scan our Mac. I accomplished this with an AppleScript that I compiled into its own application. You can do that by launching Applications -> Utilities -> Script Editor and creating a new document. Once your new document appears, enter the following code by copying and pasting it.

do_menu("Malwarebytes Anti-Malware", "Scanner", "Scan")

on do_menu(app_name, menu_name, menu_item)
try
-- This should launch and bring Malwarebytes Anti-Malware to the front
tell application app_name
activate
end tell

delay 5

-- Now we’ll kick off a scan
tell application "System Events"
tell process app_name
tell menu bar 1
tell menu bar item menu_name
tell menu menu_name
click menu item menu_item
end tell
end tell
end tell
end tell
end tell
return true
on error error_message
return false
end try
end do_menu

Compile the script, and save it to /Applications as an application named malwarebytes-automate. Run the app once, both to set up some security permissions needed and to make sure it works. The app will ask you to grant it Accessibility permission in System Preferences -> Security & Privacy -> Privacy, so make sure you do that. Run the automation app one more time, and make sure it kicks off the scan.

Now, the Magic of Keyboard Maestro Automation

Next, we’ll set up Keyboard Maestro to automatically run our malware scan once a month. Launch Keyboard Maestro, if you haven’t already, and click File -> New Macro. Give your new macro a name, then click the green and white plus sign labeled New Trigger. Choose Periodic Trigger. Next, configure the trigger to repeat every one hour between a particular almost-two-hour period of time. I chose 2 a.m. to 2:59 a.m., because I’m not likely to be using my Mac during that time.

With the time set, select the day (or days) when you want the scan to run. Remember, midnight is technically the following day, so plan accordingly.

Now that you’ve scheduled your macro, it’s time to tell it what to do. Next, click the green and white arrow labeled New Action, then choose All Actions -> Activate a Specific Action. Choose your automation script, which you should have named malwarebytes-automation. Make sure All windows is checked and “leave it at the front” is selected for If already at the front. Once done, your macro should look something like mine.

Keyboard Maestro macro to make Malwarebytes Anti-Malware scan automatically
This is my Keyboard Maestro macro to make Malwarebytes Anti-Malware scan automatically

Finally, test it out by clicking the Try button at the bottom of the window, and make sure it works. Once done, you can quit the Keyboard Maestro Editor, and rest assured that Malwarebytes Anti-Malware will scan your system automatically, keeping you safe from Trojans and other nefarious software intrusions.

10 thoughts on “Making Malwarebytes Anti-Malware Scan Automatically on Your Mac

  • Same to arrange scan with ClamXAV:

    do_menu(“ClamXAV”, “File”, “Start Scan”)
    on do_menu(app_name, menu_name, menu_item)
    try
    — This should launch and bring Malwarebytes Anti-Malware to the front
    tell application app_name
    activate
    end tell

    delay 5

    -- Now we’ll kick off a scan
    tell application "System Events"
    tell process app_name
    tell menu bar 1
    tell menu bar item menu_name
    tell menu menu_name
    click menu item menu_item
    end tell
    end tell
    end tell
    end tell
    end tell
    return true
    on error error_message
    return false
    end try

    end do_menu

  • Good to hear you gouty it working, Bruce. Strange you had so many problems. It only runs over an hour on my configuration.

    Rob1sonjr, thanks for sharing how you got it working. Great job!

  • One more tip/modification I made was to change the time range in Keyboard Maestro to 55 minutes, i.e. in this example from 11:55 pm to 12:50 am, otherwise the program runs twice during the hour.

  • Jeff,
    Thanks for the idea, and the applescript work. I also had the initial issue with the quotes, but replaced them with regular quotes. I’m not a keyboard Maestro user, but I love Hazel. Hazel can run applescripts directly it seems, but I got an error trying that method. So here is what I did. I created a new Automator workflow document. I added the action to Run Applescript and pasted your script into the window, and tested the script there. I saved the workflow document into the ~/Library/scripts folder. In Hazel, I am monitoring the Malwarebytes folder in ~/Library/Application Support/ . In general, if the log file in the Malwarebytes folder has not been modified in the last week, then Run the Automator Workflow automate-malwarebytes.

    Thanks again.

    Robbie

  • Jeff

    Thank you for the update. I followed your directions. I had issues with the “application named malwarebytes-automate” but the script ran great. I had initially saved your text as a script named “automate-malwarebytes” to my desktop. So as an alternative, I moved this script to ~/Library/Scripts and modified the Keyboard Maestro Macro.

    My applications folder is pretty full and I prefer accomplishing this task using a script instead of the “app” created by Script Editor. It works great. Please feel free to offer this as an alternative if you think it would be helpful. I was thinking of adding something to close the app (Malwarebytes Anti-Malware) after it ran but after thinking about it decided it would be better to manually close the app so that I would see any warnings in case I got infected with some kind of malware.

    Thank you again for this great idea. TMO has a great staff and more great tips for regular and power users than any other site I visit regularly. Have a great weekend.

  • Bruce,

    Try copying the entire script again. It worked fine for me with a standard copy and paste from the edited version. Make sure these apps have permission in System Preferences -> Security & Privacy -> Privacy: Malwarebytes Anti-Malware, automate-malwarebytes, and Script Editor.

  • Hi Jeff,

    I replaced quotes and that resolved the initial issue. Now on “Play” Script Editor does not like:
    end try

    Syntax Error:

    Expected end of line, etc. but found “try”.

  • Jeff,

    This looks great but I cannot get it to work. I followed your directions exactly but get the following when I attempted to compile the script:

    Syntax Error

    Expected expression, etc. but found unknown token

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WIN an iPhone 16 Pro Max!