Skip to content

Instantly share code, notes, and snippets.

@WengerK
Last active February 3, 2021 10:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WengerK/ad0c1330966522c05f504d71d29f675b to your computer and use it in GitHub Desktop.
Save WengerK/ad0c1330966522c05f504d71d29f675b to your computer and use it in GitHub Desktop.
MacOS - Trigger Notification Center when long running commands finishes

Article Ressources - MacOS - Trigger Notification Center when long running commands finishes

This is the Gist repository for my article MacOS - Trigger Notification Center when long running commands finishes.

Be aware that this article has been wrote for the Blog of Antistatique — Web Agency in Lausanne, Switzerland. A place where I work as Full Stack Web Developer.

Feel free to read it the full article on Medium or check it out on Antistatique.

function f_notifyme {
LAST_EXIT_CODE=$?
CMD=$(fc -ln -1)
# No point in waiting for the command to complete
notify "$CMD" "$LAST_EXIT_CODE" &
}
export PS1='$(f_notifyme)'$PS1
#!/usr/bin/env osascript
on run argv
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
if frontApp is not "iTerm2" then
set notifTitle to item 1 of argv
set notifBody to "succeded"
set errorCode to item 2 of argv
if errorCode is not "0"
set notifBody to "failed with error code " & errorCode
end if
display notification notifBody with title notifTitle
end if
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment