Shell Scripts
Running Scheduled Jobs
05/04/2022 09:35 AM
For reasons unworthy of deeper investigation, crontab on macOS Monterey does not actually execute cron jobs. Yes, crontab is deprecated in favor of launchctl, but let's take the path of least resistance. It just so happens that Keyboard Maestro has a cron-trigger. And it works.


Forget about mount
04/17/2022 10:58 AM
I wasted a lot of hours playing with mount_smbfs(8) and mount(8) until I found The Answer: open 'smb://username:password@server/share'. open(1) is a fine Swiss Army knife and, according to "man open", it first appeared in NextStep. Figures. :-)
reMarkable Suspend Screen Script
06/07/2021 09:34 AM
#
# Your local path and IP address will vary.
# The suspend.png file should be 1872 x 1404 at 226 DPI.
#
alias setremarkablesleepscreen='scp ~/Documents/Drawings,\ Diagrams,\ and\ Art/reMarkable/suspended.png root@192.168.0.220:/usr/share/remarkable/'
# Your local path and IP address will vary.
# The suspend.png file should be 1872 x 1404 at 226 DPI.
#
alias setremarkablesleepscreen='scp ~/Documents/Drawings,\ Diagrams,\ and\ Art/reMarkable/suspended.png root@192.168.0.220:/usr/share/remarkable/'
BASH to fix JPG timestamps
11/23/2019 11:05 AM
#! /usr/local/bin/bash
# November 23, 2019
# Downloading images from Shutterfly sets all of the file system attributes
# to the download time. This script pulls the createdate attribute from the
# EXIF data and touches the file appropriately. Empty EXIF createdate data
# is filtered.
#
# This script can obviously be used to change the timestamp of any file with
# EXIF data to the createdate.
#
for item in "$@"
do
timestamp=`exiftool -T -createdate "$item" | sed -e s/://g | sed -e "s/ //" | cut -c 1-12`
echo $item - $timestamp
if [ $timestamp != "-" ];
then
touch -t "$timestamp" "$item"
fi
done
# November 23, 2019
# Downloading images from Shutterfly sets all of the file system attributes
# to the download time. This script pulls the createdate attribute from the
# EXIF data and touches the file appropriately. Empty EXIF createdate data
# is filtered.
#
# This script can obviously be used to change the timestamp of any file with
# EXIF data to the createdate.
#
for item in "$@"
do
timestamp=`exiftool -T -createdate "$item" | sed -e s/://g | sed -e "s/ //" | cut -c 1-12`
echo $item - $timestamp
if [ $timestamp != "-" ];
then
touch -t "$timestamp" "$item"
fi
done
Shell Scripts for ProGallery Management
10/20/2019 09:02 AM
#!/usr/local/bin/bash
#
# Get the base name, create a _tn version, downsize the _tn to a max of 1280 pixels,
# and copy them to the target gallery. (Future: add a command line arg for gallery)
#
a=`basename -s .jpg $1`
cp $a.jpg ${a}_tn.jpg
sips -Z 1280 ${a}_tn.jpg
mv $a.jpg /Volumes/wwwroot/Pictures/Food
mv ${a}_tn.jpg /Volumes/wwwroot/Pictures/Food
#
# I use ProGallery - https://stacks4stacks.com/progallery/
# ProGallery uses a CSV file as the image directory source.
# The first line is labels: Title, ThumbnailPath, ImagePath.
# Images are displayed in order, so we need to add the labels
# and the new images *at the top*. Also, Title can include HTML, so I do.
#
# Strip off the header of the existing file.
grep -v Thumbnail /Volumes/wwwroot/Albums/Food.csv > /Volumes/wwwroot/Albums/Food.csv.o
# Delete the existing file.
rm /Volumes/wwwroot/Albums/Food.csv
# Create the labels for the new file
echo \"Image\", \"Thumbnail\", \"Fullsize\" > /Volumes/wwwroot/Albums/Food.csv
# Add the new image
echo '"'${a}'
'${a}'"', ../Pictures/Food/${a}_tn.jpg, ../Pictures/Food/${a}.jpg >> /Volumes/wwwroot/Albums/Food.csv
# Concatenate the old list of images to the end
cat /Volumes/wwwroot/Albums/Food.csv.o >> /Volumes/wwwroot/Albums/Food.csv
# Delete the old image list
rm /Volumes/wwwroot/Albums/Food.csv.o
# Open the gallery file to edit the Title.
open -a /Applications/BBEdit.app /Volumes/wwwroot/Albums/Food.csv
#
# Get the base name, create a _tn version, downsize the _tn to a max of 1280 pixels,
# and copy them to the target gallery. (Future: add a command line arg for gallery)
#
a=`basename -s .jpg $1`
cp $a.jpg ${a}_tn.jpg
sips -Z 1280 ${a}_tn.jpg
mv $a.jpg /Volumes/wwwroot/Pictures/Food
mv ${a}_tn.jpg /Volumes/wwwroot/Pictures/Food
#
# I use ProGallery - https://stacks4stacks.com/progallery/
# ProGallery uses a CSV file as the image directory source.
# The first line is labels: Title, ThumbnailPath, ImagePath.
# Images are displayed in order, so we need to add the labels
# and the new images *at the top*. Also, Title can include HTML, so I do.
#
# Strip off the header of the existing file.
grep -v Thumbnail /Volumes/wwwroot/Albums/Food.csv > /Volumes/wwwroot/Albums/Food.csv.o
# Delete the existing file.
rm /Volumes/wwwroot/Albums/Food.csv
# Create the labels for the new file
echo \"Image\", \"Thumbnail\", \"Fullsize\" > /Volumes/wwwroot/Albums/Food.csv
# Add the new image
echo '"'${a}'
'${a}'"', ../Pictures/Food/${a}_tn.jpg, ../Pictures/Food/${a}.jpg >> /Volumes/wwwroot/Albums/Food.csv
# Concatenate the old list of images to the end
cat /Volumes/wwwroot/Albums/Food.csv.o >> /Volumes/wwwroot/Albums/Food.csv
# Delete the old image list
rm /Volumes/wwwroot/Albums/Food.csv.o
# Open the gallery file to edit the Title.
open -a /Applications/BBEdit.app /Volumes/wwwroot/Albums/Food.csv