Workaround for Quitting MsgFiler Bug

Some users have been reporting that MsgFiler is quitting after a period of inactivity or when waking the Mac up from sleep. I have yet to reproduce this error on my end, which makes identifying the root cause of the bug frustrating.

That said, I do have a workaround that I’m recommending to users. In this article, we’ll be creating a shell script that checks whether or not Mail is running and MsgFiler is not running. If those conditions are met, MsgFiler will be launched. Second, we’ll attach this script to a cron job that runs every minute while your Mac is running.

Update: April 29, 2024: The following video goes over the instructions below. Follow along to get the script running on your system if you are experiencing this problem.

Keep MsgFiler Open Shell Script

Here is the shell script that launches MsgFiler if the Mail app is running and MsgFiler is not. Otherwise, the script does nothing. It also writes to a log file whenever MsgFiler is launched as a result of the script.

#!/bin/bash

# path to log file

LOG_FILE="/tmp/msgfiler-open.log"

# Function to check if application with specific bundle ID is running

is_app_running() {
    # Using ps and grep to check for bundle ID
    if ps aux | grep "$1" | grep -v grep > /dev/null; then
        echo "true"
    else
        echo "false"
    fi
}

# Check if Mail is running

if [ $(is_app_running "/Applications/Mail.app") = "true" ]; then

    # Check if MsgFiler 4 is running
    
    if [ $(is_app_running "/Applications/MsgFiler 4.app") = "false" ]; then
		MSG="MsgFiler is not running, starting MsgFiler."
        echo "$(date "+%Y-%m-%d %H:%M:%S") - $MSG" >> $LOG_FILE
        open -ga "/Applications/MsgFiler 4.app"
    fi
fi

Installation Instructions

  1. Copy and paste the code above into a text file called keepMsgFilerRunning.sh.
  2. Go to the Finder.
  3. Choose Go to Folder from the Go menu.
  4. Enter /usr/local/bin and press Return.
  5. Drag the file into the /usr/local/bin folder that appears in the Finder. You may need to authenticate using an Administrator password to save the file here.
  6. Open the Terminal application.
  7. Make the script executable by typing the following command in Terminal and pressing Return:

    chmod +x /usr/local/bin/keepMsgFilerRunning.sh

Testing the Script

You can test the script by performing the following actions:

  1. Quit MsgFiler.
  2. Open Mail.
  3. Open Terminal.
  4. Type the following command and press Return.

bash /usr/local/bin/keepMsgFilerRunning.sh

You should see MsgFiler 4 launch. To view the log file, you can enter the following command in Terminal and press Return:

open /tmp/msgfiler-open.log

If MsgFiler 4 was opened as a result of the script, you’ll see a line of text similar to the following:

2024-04-25 10:29:10 - MsgFiler is not running, starting MsgFiler.

Getting the Script to Run Every Minute

Next, we’ll configure the script to run every minute on your Mac. This involves adding an entry to your Mac’s crontab. Cron is a job-scheduler for Unix-like operating systems like macOS. There are many utilities for managing your crontab, which is a configuration file which tells cron how often to run a script. Here’s how to add the keepMsgFilerRunning.sh script to your crontab.

  1. Open Terminal.
  2. Type crontab -e and press Return.
  3. In the screen that appears, type the letter i. This will set the editor into Insert mode.
  4. Type the following string and press Return:

    * * * * * bash /usr/local/bin/keepMsgFilerRunning.sh
  5. Press Escape.
  6. Type the following string and press Return:

    :x
  7. This will save the crontab.

Now, every minute, the script will run and MsgFiler will automatically re-launch if the two conditions are satisfied:

  • Condition 1: Mail is running
  • Condition 2: MsgFiler is not running

Limitations

When MsgFiler opens, it becomes the frontmost application. There is a way to hide MsgFiler when it is opened via the script, but it requires a slightly modified version of the script. This modification requires granting permission for cron to be able to use System Events from the Privacy & Security section of System Settings.

#!/bin/bash

# path to log file

LOG_FILE="/tmp/msgfiler-open.log"

# Function to check if application with specific bundle ID is running

is_app_running() {
    # Using ps and grep to check for bundle ID
    if ps aux | grep "$1" | grep -v grep > /dev/null; then
        echo "true"
    else
        echo "false"
    fi
}

# Check if Mail is running

if [ $(is_app_running "/Applications/Mail.app") = "true" ]; then

    # Check if MsgFiler 4 is running
    
    if [ $(is_app_running "/Applications/MsgFiler 4.app") = "false" ]; then
    
	    # In order to make the MsgFiler 4 disappear after opening, we have to switch to two applications.
	    # The following AppleScript retrieves the name of the current frontmost application and
	    # another application which is currently visible (not hidden) on the screen.
	    
        frontmost_app=$(osascript -e 'tell application "System Events" to name of first application process whose frontmost is true')
        another_app=$(osascript <<EOF
try
	tell application "System Events"
		return name of first application process whose frontmost is false and visible is true
	end tell
on error
	return "$frontmost_app"
end try
EOF
)
               
        MSG="MsgFiler is not running, starting MsgFiler."
        echo "$(date "+%Y-%m-%d %H:%M:%S") - $MSG" >> $LOG_FILE
        open "/Applications/MsgFiler 4.app"
        
        sleep 1
        
        # Switch to two applications to make the MsgFiler 4 window disappear.
        
        osascript -e "tell application \"$another_app\" to activate"
        osascript -e "tell application \"$frontmost_app\" to activate"
    fi
fi

Here, we find the current frontmost application, along with another application which is currently visible. After opening MsgFiler, the script activates both applications, which has the effect of making the MsgFiler window hidden.

Isolating the Bug

I’ll continue to work on determining what is causing the bug, but until then, I’d encourage users to use this bash script and cron workaround.

Let me know if you have any questions getting this to work.

14 thoughts on “Workaround for Quitting MsgFiler Bug”

    1. Send me an email to support (at) msgfiler (dot) com, and we’ll work through this. Provide a description on the type of email accounts you have (i.e. how many Gmail accounts, iCloud, etc.).

  1. I’ve noticed this happening as well. I just start MsgFiler in that case. I have a question about the every-minute script though. Does that add any noticeable load on the MBP?

    Thanks.

    1. I just started using it to see if I can replicate the crashing bug. The script is quite innocuous and doesn’t do anything if Mail is closed or if MsgFiler is running (when Mail is open). So the impact on load should be minimal. You can adjust the interval that the cron job gets called by changing * * * * * to */5 * * * * in the crontab entry.

  2. Good morning. 🙂 Thanks for your post on this. I’d just started to become aware that msgfiler seemed to be quitting itself at random, so this was quite timely. It’s odd because I don’t get any sort of “MsgFiler has unexpected quit” or whatever the message is now. It’s like it gracefully shuts itself down.

    Crontab is only slightly less mysterious to me than regex, so I really appreciated the detailed guide. I did have to use sudo to make changes in /usr/local/bin; I suspect most people will given Apple’s aggressive security policies.

    I used the first version of the script, as I actually wanted to see the window if it relauched. It’s already fired off once.Good luck on the bug hunt!

  3. I haven’t seen this either, but what I have seen, and I haven’t been able to confirm it with a test case, is that sometimes my Favorites get forgotten.

  4. I just set this up because I do have this issue. It seems that MsgFiler quits repeatedly within 7 minutes on my Mac.

    ~ cat /tmp/msgfiler-open.log
    2024-04-30 18:58:50 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 04:21:06 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 04:28:01 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 04:35:01 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 04:42:01 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 04:49:01 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 04:56:00 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 05:03:01 – MsgFiler is not running, starting MsgFiler.
    2024-05-01 05:10:01 – MsgFiler is not running, starting MsgFiler.

    Even with using the script that uses System Events, the script is not usable as every 7 minutes, it flashes MsgFiler to the front and then switched back to the app that was in the foreground prior to the script firing.

    @Adam if there are logs I can grab for you to help debug, just let me know what you want/need.

    1. I’ve submitted a new version of MsgFiler for review to the App Store. I may have found the problem, but not sure. The fact that it’s quitting regularly after 7 minutes is very odd. Are there any crash logs for the app in the Console > Crash Reports app?

      1. I just double checked the Console and there’s nothing in the Crash Reports for MsgFiler.

      2. Got it. Send me an email to support (at) msgfiler (dot) com. Want to get a system report from you to see what apps are running that might be in conflict.

Leave a comment

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