Korn Shell Spreadsheet Hyperlink Listener Tutorial

Korn Shell Spreadsheet Hyperlink Listener Tutorial

Korn Shell Spreadsheet Hyperlink Listener Tutorial

We want to build on the “listener” thoughts of yesterday’s Perl CGI Spreadsheet Download Detector Tutorial‘s …

  • Korn Shell based “listener” of macOS Spreadsheet download “say” audio hyperlinks … to genericize, today, with …
  • Korn Shell based “listener” of macOS Spreadsheet download with any hyperlink URL for any downloaded Spreadsheet

… as a product feeling more like a tool.

Yesterday’s work, with all the help, thanks, gave us a good framework to tweak, further, a scheduled and interactive combination of modes of use, used in Korn Shell lookforhyperlinks.ksh


#!/bin/ksh
# lookforhyperlinks.ksh
# RJM Programming
# February, 2023
# Look for hyperlinks in downloaded Spreadsheets
# crontab usage supply an additional argument (onto a first emailee argument, perhaps) ... or to do as a one off execution usage
# Thanks to ...
# https://www.unix.com/unix-for-dummies-questions-and-answers/123644-converting-binary-file-readable-format-ksh.html
# https://stackoverflow.com/questions/26968159/list-of-files-modified-1-hour-before
# https://www.unix.com/shell-programming-and-scripting/247464-awk-combined-if.html
# https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command

modeopencurl="open";
one="1";
two="2";
qt="\"";
emailto="";
if [ ! -z "$1" ]; then
if [ "`echo $1`" == "curl" ]; then
modeopencurl="curl";
shift;
fi
fi
if [ ! -z "$1" ]; then
if [ "`echo $1 | tr '@' 'x'`" != "`echo $1`" ]; then
emailto="$1";
shift;
fi
fi

while test "$one" -ne "$two" ; do
axls=`find $HOME/Downloads -name "*.xls*" -type f -mmin 1`;
if [ ! -z "$axls" ]; then
res=`hexdump -C "${axls}" | sed '/[.][|][.]/s//.!@!./g' | cut -f2 -d '|' | sed '/[.][!][@][!][.]/s//.|./g' | tr -d '\n' | sed -e 's/=.s.a.y./=.S.a.Y./g' | tr -d "'" | cut -d':' -f 2- | grep '.h.t.t.p.' | sed '/[.][.][.][.]/s//~/g' | sed '/[%][.]2[.]0/s//"/g' | awk -F'.h.t.t.p.' '{for(i=2;i<=NF;i++){if($i){split($i,a,"~");print "http" a[1] "@";}}}' | sed '/[.][.]/s//.~/g' | sed '/[.]/s///g' | sed '/[~]/s//./g' | sed '/\_record\.php\?docronwork\=\@/s//SaY/g' | sed '/[@]/s//";\n/g'`
if [ ! -z "$res" ]; then
if [ -z "$1" -a -z "$emailto" ]; then
if [ "$modeopencurl" = "curl" ]; then
echo $res | sed -e 's/ http/"; \ncurl "http/g' | awk 'NR==1,/http/{sub(/http/, "curl \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh
else
echo $res | sed -e 's/ http/"; \nopen "http/g' | awk 'NR==1,/http/{sub(/http/, "open \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh
fi
ksh /tmp/ideatwo.ksh &
else
if [ ! -z "$emailto" ]; then # no -e 's/=/%3d/g' below
echo $res | sed -e 's/";";\n/\n/g' | sed -e 's/";\n/\n/g' | sed -e 's/</%3c/g' -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b%0a%0a/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/`/%60/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g' > /tmp/ideatwo.ksh
bxls=`echo "$axls" | sed -e 's/</%3c/g' -e 's/%/%25/g' -e 's/ /%20/g' -e 's/!/%21/g' -e 's/"/%22/g' -e 's/#/%23/g' -e 's/\$/%24/g' -e 's/\&/%26/g' -e 's/'\''/%27/g' -e 's/(/%28/g' -e 's/)/%29/g' -e 's/\*/%2a/g' -e 's/+/%2b/g' -e 's/,/%2c/g' -e 's/-/%2d/g' -e 's/\./%2e/g' -e 's/\//%2f/g' -e 's/:/%3a/g' -e 's/;/%3b%0a%0a/g' -e 's//%3e/g' -e 's/?/%3f/g' -e 's/@/%40/g' -e 's/\[/%5b/g' -e 's/\\\\/%5c/g' -e 's/\]/%5d/g' -e 's/\^/%5e/g' -e 's/_/%5f/g' -e 's/{/%7b/g' -e 's/|/%7c/g' -e 's/}/%7d/g' -e 's/~/%7e/g' | tr -d '$'`
# restwo=`echo $res | sed '/"/s//@/g' | sed "/@/s//'/g"`
#cat /tmp/idea.ksh | mailx -s "Proposed macos say audio ideas ..." $1;
open "mailto:${emailto}?subject=Proposed%20hyperlinks%20in%20downloaded%20spreadsheet%20`echo ${bxls}`%20...&body=`cat /tmp/ideatwo.ksh`"
if [ "$modeopencurl" = "curl" ]; then
echo $res | sed -e 's/ http/"; \ncurl "http/g' | awk 'NR==1,/http/{sub(/http/, "curl \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh
else
echo $res | sed -e 's/ http/"; \nopen "http/g' | awk 'NR==1,/http/{sub(/http/, "open \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh
fi
else
if [ "$modeopencurl" = "curl" ]; then
echo $res | sed -e 's/ http/"; \ncurl "http/g' | awk 'NR==1,/http/{sub(/http/, "curl \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh
else
echo $res | sed -e 's/ http/"; \nopen "http/g' | awk 'NR==1,/http/{sub(/http/, "open \"http")} 1' | sed -e 's/";";"/;"/g' > /tmp/ideatwo.ksh
fi
ksh /tmp/ideatwo.ksh &
fi
fi
fi
fi
if [ -z "$1" ]; then
sleep 60
else
two=$one
fi
done
exit

… usable for macOS command “verbs” open or curl

Interactive
continuous
open URL
Interactive
continuous
in background
curl URL
Interactive
continuous
emailing
in background
open URL
Scheduled
audio
curl URL
Scheduled
audio
email
open URL
ksh ./lookforhyperlinks.ksh ksh ./lookforhyperlinks.ksh curl & ksh ./lookforhyperlinks.ksh rmetcalfe15@gmail.com & * * * * * ksh ./lookforhyperlinks.ksh curl * * * * * ksh ./lookforhyperlinks.ksh rmetcalfe15@gmail.com

If this was interesting you may be interested in this too.

This entry was posted in Uncategorised. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *