'Restart TotalFinder' in menu bar, on addition to existing 'Restart Finder'

Because of a bug in Finder (not TotalFinder), I have to restart/relaunch Finder often to make the icons on the Desktop match the content of the ‘~/Desktop’ folder. Sometimes, new files don’t appear, sometimes, deleted files still have icons on the Desktop.

I understand why restarting Finder doesn’t automatically restart TotalFinder, this may cause infinite restart loops.

I made a script to fully automate restarting Finder and TotalFinder from the command line. It’s included below for anyone else having the same issue I do.

A much better and more convenient solution would be to have a ‘Restart TotalFinder’ entry in the menu bar next to the existing ‘Restart Finder’ entry.

#!/usr/local/bin/python2.7
# -*- coding: utf-8 -*-

# standard packages
import os
import signal
import sys

# non-standard packages which may need to be installed
try:
  import psutil
except ImportError:
  print("psutil not installed, do it by running:")
  print("pip install psutil")
  sys.exit(1)

def killall_wait(match_string):
  # get list of process whose info contain 'match_string'
  cmd = os.popen("ps ax | grep " + match_string + " | grep -v grep")
  ps_lines = cmd.read().split("\n")[:-1]
  cmd.close()
  del cmd
  # extract pids
  pids = [int(ps_line.split()[0]) for ps_line in ps_lines]
  del ps_lines
  # issue kill commands
  for pid in pids:
    os.kill(pid, signal.SIGKILL)
  # wait for kill commands to complete
  for pid in pids:
    while psutil.pid_exists(pid):
      pass

if __name__ == "__main__":
  # kill all Finder related process (including TotalFinder if running)
  killall_wait("Finder")
  # Finder will automatically restart (fixing desktop as expected side effect),
  # we need to restart 'TotalFinder', not done automatically to avoid crashing
  # loop.
  os.popen("open /Applications/TotalFinder.app").close()

You can restart Total Finder from the system applications folder. That works fine.