Decided to copy decades of digital photos from Photos (nee iPhoto) to NAS. If your client doesn’t decode and your server doesn’t transcode HEIC then you’ll need to convert HEIC image files. Unlike iPhoto, Photos makes the task of exporting the library in a sane manner with keywords intact unnecessarily impossible, or nearly so. Turns out some brave person created a Python script, osxphotos, to accomplish that task. It’s certainly robust and installation failed for me using Mac Ports (likely due to the age of my system and plenty of outdated deps and other crud from unmaintained packages). But I digress. The instructions for ‘pip’ worked no sweat.
Continue readingCategory Archives: Code
Avoid the AI lander on Google search
This is mostly for my own benefit. What it is is the URL that can be used to add a “Search Engine” in Firefox and friends preferences/settings. Possibly others as well. The GET pair udm=14 puts you at the “Web” results tab…I guess…instead of “All” which we all know is the devil. The GET pair tbs=li:1 is “Verbatim” which we all know is practically a placebo at this point. newwindow and client should be self explanatory.
https://www.google.com/search?udm=14&tbs=li:1&newwindow=1&client=firefox-b-1-d&q=%s
Place PDF 2-up for perfect bind
I don’t do perfect binding, so I don’t have or know of tools that will do what is needed to paginate for cut and stack layout. The Fiery print controller will do that, but only 2-up. Which is fine until you need 4-up. So to do that I needed a 2-up file that could then also be printed 2-up. Clear as mud, as they say.
Continue readingParse USPS Clink-n-Ship receipt e-mail
UPDATE: I worked this out at home on Manjaro which uses GNU ‘date’ (I assume), but macOS ‘date’ isn’t as foolproof. Also can’t be used against stdin apparently. :\
The purpose being to pare their e-mail down to just the receipt part so you can print as few pages as possible.
Used to do this with AppleScript using Mail.app. Going to Thunderbird means a different option needs to be found. Using a Folder Action can do that by calling this script:
#!/bin/bash
# Set to true to write variables to a tmp file (/tmp/USPS_debug.txt).
_debug=false
# cat contents of .eml file, awk removes newlines after '=', tr removes the rest.
_mess="`cat "$1" | awk '1' RS='=\r\n' ORS= | tr -d '\r\n'`"
if [ $_debug = true ]; then echo "_mess: $_mess" > /tmp/USPS_debug.txt; fi
# Extract the UTC 0 date from the Date header, date converts it to locale
# The Linux/GNU version of 'date' needs less massaging than the one included with macOS. Same for 'sed', actually.
#_date="`echo $_mess | sed -E 's/.+Date: ([A-Za-z]{3}, [0-9]+? [A-Za-z]{3} [0-9]{4} [0-9]+(:[0-9]+){2}).+/\1 UTC/g' | date -f -`"
# The below two _date var lines are for macOS. You could subshell it into one line, but *meh*.
_date="`echo $_mess | sed -E 's/.+Date: ([A-Za-z]{3}, [0-9]{1,2} [A-Za-z]{3} [0-9]{4} [0-9]{2}(:[0-9]{2}){2}).+/\1/g'`"
if [ $_debug = true ]; then echo "_date: $_date" >> /tmp/USPS_debug.txt; fi
_date="`date -j -v-7H -f \"%a, %d %b %Y %R:%S\" \"$_date\"`"
# Extract the order number.
_order="`echo $_mess | sed -E 's/.+>([a-z0-9]{8}(-[a-z0-9]{4}){3}-[a-z0-9]{12})<.+/\1/g'`"
if [ $_debug = true ]; then echo "_order: $_order" >> /tmp/USPS_debug.txt; fi
# Extract the section containing the juicy bits, remove more e-mail chaff, fix the tracking link, break up that one big line of code.
_sec4="`echo $_mess | sed -E -e 's/.+START SECTION 4 -->(.+)<!-- END SECTION 4.+/\1/g' -e 's/(=3D)|(=C2)|(=AE)//g' -e 's/(.+)<a hrefh(.+[0-9]{34})>(.+)/\1<a href=\"h\2\">\3/g' -e 's/([a-z]+>) (<)/\1\n\2/g'`"
if [ $_debug = true ]; then echo "_sec4: $_sec4" >> /tmp/USPS_debug.txt; fi
# Get down to the nitty gritty.
echo "<html>
<head>
<style>
body { width: 576px; font-size: 0.8em; }
.pt-5 {margin-bottom: 0.5em; margin-top: 0em; }
.bold {line-height: 1em !important; }
</style>
</head>
<p class=\"pt-5\">Received: $_date</p>
<p class=\"pt-5\">Order # $_order</p>
$_sec4
</body>
</html>" > /tmp/USPS-receipt.html
open /tmp/USPS-receipt.html
Only problem I have found is the dragging of messages out of Thunderbird can be interrupted with a replace file warning at the temp folder being used to first store the dragged message.
Hot Folder Folder Action
Updating this with the -o raw lp option since I discovered that, without, it will default to whatever is providing default papersize. In my case US Letter. If that option does not work for you, naturally edit it out.
(*
strawhousepig.net
Hot folder action! The jokes write themselves.
Takes the name of the folder it is attached to and sends received items to the
corresponding printer.
How to: Find a place to keep a folder that is named as the printer ID (not the name), which
can be found using 'lpstat -v', or seen in the cups web interface, or as "Device name"
in the GUI printer settings, and attach this script to it as a Folder Action. The run handler
is here just for testing, but could be set-up to send files selected in the Finder.
I keep my hot folders in a child folder of the Desktop, so it's fairly convenient to drop
items into. If dropping isn't your bag, you could place the hot folder in ~/Library/PDF Services,
or write a seperate script or workflow in PDF Services to have the best of both worlds.
*)
set send_raw to {"C3080__hold_"}
global send_raw
on adding folder items to this_folder after receiving these_items
my do_thing(these_items, this_folder)
end adding folder items to
set this_folder to (choose folder)
set these_items to {}
tell application "System Events" to set these_items to every item of (this_folder) whose name does not start with "."
my do_thing(these_items, this_folder)
on do_thing(these_items, this_folder)
set _this to name of (info for this_folder)
if _this is in send_raw then
set add_opts to "-o raw " --trailing space here
else
set add_opts to ""
end if
repeat with i in these_items
set i to quoted form of POSIX path of (i as alias) -- Comment this and the shell scripting if you want to try the "System Events" route.
set _script to "lp " & add_opts & "-d " & _this & " " & i & " && mv " & i & " ~/.Trash/"
--log _script --for debuging
do shell script _script
-- tell application "System Events" to print i with properties {target printer:name of (info for this_folder)} -- Bugged. Does not work. *smh*
end repeat
return
end do_thing
Printing black from Firefox
…is a mixed bag.
By printing “black” I mean printing using only black ink or toner, also known as grayscale. This works on Windows (10) but not macOS. Unsure about GNU/Linux OSes, but according to this page—
Also from that page is a hint to enable it. If you open about:config (from the location bar of Firefox) and search for “monochrome” you can find (or create if need be) a setting titled print.cups.monochrome.extra_settings and enter the appropriate variable and value for your printer. Which may require some sleuthing inside the PPD for your printer as not all companies use the same pair. In my case, printing to the parasite (an EFI/Fiery controller) on my Konica/Minolta “digital press” requires a value of EFColorMode:Grayscale in the above mentioned setting.
Also works in Thunderbird.
AppleScript + friends to generate proof image of PDF
Often when you create artwork for use as part of your making a living you don’t charge for it and just keep it to yourself. You also have to show it to the customer for approval, but sending them the original art means risking them taking it Someplace Else. You can of course charge up front or after the fact, but you still risk being out priced by the shop not doing the layout. So my best practice has been to create a lower than optimal resolution image with a watermark (aka stamp) placed over the artwork. Continue reading
ps2pdf droplet
The long running gag around here is I use old software that works with old hardware. Fun. Recently I was sent a PostScript file to output to film, but the version of Distiller I use choked on it. Illustrator CS2 could open it, but unbeknownst to me it only imports the first page. More fun.
Continue readingShell script to write today’s and next weekday’s date
As is this script has limited purpose, and includes RTF markup not useful to anyone else other than as example.
But, what is useful is the date function that increments to the next ‘weekday’ day of week. Be aware that this script formats into Americanized short date (e.g., 12-31-69). Which may seem odd since I just wrote (and re-wrote a couple dozen times) a script to obliterate that format in file names. Except that I’m using this script to fill out the dates on an order form where the dates are expected to be the familiar, informal conversational format used in the US. Whereas for a file name in a computer, YYYY-MM-DD is a useful sorting method.
A lot of ‘others’ don’t take the time to realize that. I’ve run into vandalized man pages for date that attempt to make admonitions against the US informal conversational date format into some moral indictment. That format appears from the way one would speak the date in the US: December thirty-first, nineteen sixty-nine. The same as one would use more words to say: The thirty-first of December, nineteen sixty-nine. It’s not hard, Europeans. 😀
Also posting the plist used with launchd to run this script every morning.
#! /bin/sh
# http://strawhousepig.net/
# Used with launchd to run every morning user is logged in.
# Runs "at load" in case log in happens after the scheduled time (8:15).
# Purpose: $outfile is meant to be placed as a linked text object in InDesign document.
# But, InDesign (CS2) won't keep text style when updating the link
# unless you load it up with (double escaped) RTF markup. :|
outfile=~/Documents/date-today.rtf
# Today's (formatted) date.
todate=$(date -j "+%m-%d-%y" | sed -E 's/0([0-9])/\1/g')
# Next weekday:
# Use today's day-of-week to count days until Monday if day-of-week is greater than 4 (Thursday).
dofw=$(date +%w)
nextdate=$(date -j -v+$(( ( $dofw>4 )?8-$dofw:1))d "+%m-%d-%y" | sed -E 's/0([0-9])/\1/g')
# ProTip: Use '$todate' and '$nextdate' as placeholder text in your RTF file.
# ie., format a sample RTF file then open, copy, & paste it as (double escaped) plain text here.
rtf="{\\\rtf1\\\ansi\\\ansicpg1252\\\cocoartf1038\\\cocoasubrtf360
{\\\fonttbl\\\f0\\\fswiss\\\fcharset0 Helvetica;}
{\\\colortbl;\\\red255\\\green255\\\blue255;}
\\\margl1440\\\margr1440\\\vieww9000\\\viewh8400\\\viewkind0
\\\pard\\\tx720\\\tx1440\\\tx2160\\\tx2880\\\tx3600\\\tx4320\\\tx5040\\\tx5760\\\tx6480\\\tx7200\\\tx7920\\\tx8640\\\sb160\\\ql\\\qnatural\\\pardirnatural
\\\f0\\\fs32 \\\cf0 $todate\\\
$nextdate}"
printf "$rtf" > "$outfile"
Launchd properties file (reflects the above code being named “date-today-write-to-file.sh” and placed into the user’s ‘Documents’ folder) should be placed in the LaunchAgents folder of the users Library folder, not the root Library (e.g., ~/Library/LaunchAgents/date-today.write-to-file.plist) and loaded with launchctl load ~/Library/LaunchAgents/date-today.write-to-file.plist
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>date-today.write-to-file</string>
<key>Program</key>
<string>/Users/EXAMPLE/Documents/date-today-write-to-file.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>08</integer>
<key>Minute</key>
<integer>15</integer>
</dict>
</dict>
</plist>
AppleScript to write Finder tag from folder name
This is a weird one that came from a request on reddit.
Not really useful (to me) as intended, but I envision it could be re-worked to a FolderAction that would help tag photos. Especially if coupled with a file sorter. But incorporating the tag writing into the sorter would be much more sane.
The commented out do shell script lines were meant as a way to read existing tags and then add the folder name after them. That didn’t work out thanks to xattr -p spitting out hexadecimal instead of a plist array, which is the format used when writing the tags. WTF, Apple…
-- http://strawhousepig.net/
on run
set _drop to {}
set end of _drop to (choose folder)
my do_it(_drop)
end run
on open _drop
my do_it(_drop)
end open
on do_it(_drop)
display dialog "WARNING: This script will overwrite ALL tags of files in or targeted from the opened folder with the name of the opened folder." with icon 0
repeat with d in _drop
if folder of (info for d) is true then
set f to {}
try
tell application "Finder"
set _tag to "" & name of (info for d) & ""
set _files to (every item in d)
repeat with f in _files
if alias of (info for f as alias) is true then
set f to original item of f as alias
end if
-- 'xattr -p' will print the value for a named metadata ID. Naturally that value is printed as hexadecimal. :|
-- set f_plist to (do shell script "xattr -p com.apple.metadata:_kMDItemUserTags " & quoted form of POSIX path of (f as alias))
-- set _tag to (do shell script "echo \"" & f_plist & "\" | egrep -o \"*\"") & _tag
set tag_plist to "" & _tag & ""
do shell script "xattr -w com.apple.metadata:_kMDItemUserTags " & quoted form of tag_plist & " " & quoted form of (POSIX path of f)
end repeat
end tell
on error _err
display dialog _err
end try
end if
end repeat
end do_it