commit 237f903081b9635a641aca346f1a79b0203c904a
parent f69ff609a2d249a75daf6c2d80ff22ec66a1dbb5
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 9 Jan 2019 22:29:17 +0100
Add message script
Diffstat:
A | links/bin/message | | | 87 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 87 insertions(+), 0 deletions(-)
diff --git a/links/bin/message b/links/bin/message
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+set -e
+#set -v
+
+#keyboard-layout-switch.sh dk
+
+# server running macos
+host="adamsgaard.dk"
+user="ad"
+port="12344"
+
+version=1.0
+
+function show_help {
+ echo "usage: ${0##*/} [OPTIONS] RECIPIENT [RECIPIENT2 [RECIPIENT N]]"
+ echo "will send stdin to recipients through $user@$host"
+ echo "OPTIONS are one or more of the following:"
+ echo " -p, --prompt show interactive dmenu prompt, otherwise read stdin"
+ echo " -h, --help show this message"
+ echo " -v, --version show version and license information"
+ echo " -- do not consider any following arguments as options"
+ echo "${0##*/} requires ssh access to the system."
+}
+
+function show_version {
+ echo "${0##*/} version $version"
+ echo "Licensed under the GNU Public License, v3+"
+ echo "written by Anders Damsgaard, anders@adamsgaard.dk"
+ echo "https://gitlab.com/admesg/dotfiles"
+}
+
+function die {
+ printf '%s\n' "$1" >&2
+ exit 1
+}
+
+
+prompt=0
+while :; do
+ case "$1" in
+ -h|-\?|--help)
+ show_help
+ exit 0
+ ;;
+ -v|--version)
+ show_version
+ exit 0
+ ;;
+ -p|--prompt)
+ prompt=1
+ ;;
+ --) # end all options
+ shift
+ break
+ ;;
+ -?*)
+ die 'Error: Unknown option specified'
+ ;;
+ *) # No more options
+ break
+ esac
+ shift
+done
+
+
+function send_message {
+ cmd="osascript -e 'tell application \"Messages\" to send \"$2\" to buddy \"$1\"'"
+ ssh -q -p "$port" "$user"@"$host" -t "$cmd"
+}
+
+if [ "$prompt" = 1 ]; then
+ names="Susan Louise Damsgaard Sonnesen\nAnders Damsgaard\nJesper Hannibalsen\nSimon Svendsen\nNiels Christensen\nAnne Grethe Damsgaard Christensen\nLars Damsgaard Fink"
+ recipient=$(echo -e "${names[@]}" | dmenu -i -p "To:" || exit 1)
+ msg="$(echo ' ' | dmenu -i -p 'Message:')"
+ send_message "$recipient" "$msg"
+ exit 0
+else
+ # stdin
+ [ $# -lt 1 ] && die 'Error: No RECIPIENT[S] specified'
+ msg="$(cat)"
+fi
+
+# loop over RECIPIENT[S]
+for recipient in "$@"; do
+ send_message "$recipient" "$msg"
+done
+