Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Last active August 7, 2025 20:24
Show Gist options
  • Save jonpryor/63871805c0e957e747ac2f992644e589 to your computer and use it in GitHub Desktop.
Save jonpryor/63871805c0e957e747ac2f992644e589 to your computer and use it in GitHub Desktop.
macOS script which executes the command line, and when the command finishes posts a macOS notification that the command has finished, it's time(1) info, and the exit code.
#!/bin/sh -e
TIMEFILE=`mktemp -t exec-notify` || exit 1
EXIT_CODE=0
/usr/bin/time -o "${TIMEFILE}" "$@" || EXIT_CODE=$?
cat "${TIMEFILE}"
echo exit=$EXIT_CODE
MESSAGE="exec “$1 …”\ntime: `cat ${TIMEFILE}`\nexited: $EXIT_CODE"
rm "${TIMEFILE}"
osascript -e "display notification \"$MESSAGE\" with title \"Terminal.app\""
exit $EXIT_CODE
@jonpryor
Copy link
Author

jonpryor commented Aug 7, 2025

Example:

% exec-notify.sh some very long command
… output of `some very long command`…
      100.20 real        31.88 user        25.83 sys
exit=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment