Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Submitted on September 9, 2020 at 04:48 PM

close-apps.sh (Bash)

#!/bin/bash

# Creates a comma-separated String of open applications and assign it to the APPS variable.
APPS=$(osascript -e 'tell application "System Events" to get name of (processes where background only is false)')

# Convert the comma-separated String of open applications to an Array using IFS.
# http://stackoverflow.com/questions/10586153/split-string-into-an-array-in-bash
IFS=',' read -r -a myAppsArray <<< "$APPS"

# Loop through each item in the 'myAppsArray' Array.
for myApp in "${myAppsArray[@]}"
do
  # Remove space character from the start of the Array item
  appName=$(echo "$myApp" | sed 's/^ *//g')

  # Avoid closing the "Finder" and your CLI tool.
  # Note: you may need to change "iTerm" to "Terminal"
  if [[ ! "$appName" == "Finder"
     && ! "$appName" == "iTerm"
     && ! "$appName" == "firefox"  # <-------------------- Add another app to exclude
     && ! "$appName" == "Safari" ]]; then # <-------------- and another one, etc ...

    # quit the application
    osascript -e 'quit app "'"$appName"'"'
  fi
done