Skip to content

Instantly share code, notes, and snippets.

@majick
Created July 5, 2025 02:48
Show Gist options
  • Select an option

  • Save majick/123536197b9c446be30db6f63f083a95 to your computer and use it in GitHub Desktop.

Select an option

Save majick/123536197b9c446be30db6f63f083a95 to your computer and use it in GitHub Desktop.
Run a single-shot .command file on macOS without ugly Terminal bullshit
#!/bin/sh
#
nohup [DO_WHATEVER_YOU_WANT_HERE] 2> /dev/null > /dev/null &
# The magic incantation to:
# a. Make Terminal willing to close windows
# b. Quit the terminal after this .command file runs
# c. Get rid of Terminal from the Recent Apps list (because nobody runs Terminal)
#
# We're being clever with subshells here because Terminal doesn't want to die.
#
# Terminal is a piece of shit.
#
# a. Fuck this default pref of leaving dead windows.
defaults export com.apple.Terminal - \
| plutil -replace "Window Settings".Basic.shellExitAction -integer 1 -o - - \
| defaults import com.apple.Terminal
# b. call applescript host to kill the fucking terminal, which will now die.
( sleep 1; osascript -e 'tell application "Terminal" to quit' 2> /dev/null >/dev/null & )
# c. Get rid of the ugly and confusing icon. Requires dockutil.
( nohup dockutil --remove Terminal 2> /dev/null > /dev/null & )
# TODO: just make command files only ever run in iTerm. Except iTerm pops a tab instead of
# a window which is hot garbage. Tabbed terminal windows are trash.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment