Author Archives: Kevin

Auto-backup of Photos Library.photoslibrary when portable drive is attached

This script relies on Folder Actions to fire it once it is attached to /Volumes and the appropriately named hard drive is plugged in. I use it to update my off-site photo backup drive.

Settings in the script are commented with instructions, which are hopefully clear enough. It does mention iPhoto, because it was written when iPhoto was a thing. A good thing, a great thing even. Now… *meh*

The options for rsync are fairly standard (recursive, preserve times, extended attributes, and skip files already on the backup). The path to rsync is from OS X shipping with a version of rsync that was unbearably slow and me installing a newer version. I’m not sure when Apple ditched the older rsync version, but it sure wasn’t soon enough. I’m leaving it here for example purposes, but this script will fail if you don’t have an rsync binary there.

-- The name of the physical disk.
property top_drive : "Portable HDD"

-- The name of the disk image file.
-- If it is beyond root of top_drive, the (non-POSIX) path will need to be added. ie "backups:iPhoto backup.dmg"
property iPhoto_dmg : "Photos backup.sparseimage"

-- The name of the disk image drive.
property iPhoto_drive : "Photos backup"

-- POSIX path to iPhoto Library (Default is ~/Pictures/iPhoto Library).
property iPhoto_lib : quoted form of (POSIX path of ((path to pictures folder) as text) & "Photos Library.photoslibrary")

-- rsync options
property rsync_options : "-rtE --ignore-existing"

-- Path to rsync binary.
property rsync_path : "/usr/local/bin/" -- Leave blank ("") if not using a user installed version of rsync.

on logErr(the_msg, the_num)
do shell script "logger '" & "iPhoto backup: " & the_msg & " (" & the_num & ")'"
end logErr

on adding folder items to this_folder after receiving added_items
set new_item to item 1 of added_items as text
if new_item is (top_drive & ":") then
tell application "Finder"
try
open top_drive & ":" & iPhoto_dmg as alias
delay 10
on error errMsg number errNum
my logErr(errMsg, errNum)
end try
end tell
set n to 0
try
set rsync_options to rsync_options & " "
repeat until n = 10
tell application "Finder" to set all_drives to name of every disk
if iPhoto_drive is in all_drives then
set start_time to current date
set rsync_it to (do shell script rsync_path & "rsync " & rsync_options & iPhoto_lib & " " & quoted form of ("/Volumes/" & iPhoto_drive))
set total_time to (current date) - start_time
my logErr("Done", "" & total_time & " sec")
exit repeat
else
delay 6
set n to n + 1
end if
end repeat
tell application "Finder" to eject disk iPhoto_drive
display dialog "iPhoto backup complete." & return & return & "You may now eject the disk \"" & top_drive & "\"." with icon 2
on error errMsg number errNum
my logErr(errMsg, errNum)
display dialog "Oops! An error occurred. :(" & return & return & errNum & " : " & errMsg with icon 0
end try
end if
end adding folder items to

Using Netatalk & CUPS

Using 20+ year old hardware is as much a curse as it is a blessing.

Set-Up:

Imagesetter (AccuSet 1000) – RIP (PowerMac 7500) – CUPS server (Raspberry Pi) – Clients (OS X 10.5, macOS 10.12)

The OS X 10.5 client currently serves as an MDNS print server for the newer OS machine since that is the last Macintosh OS version to speak AppleTalk, which the even older RIP requires (thankfully via ethernet).

In this day and age OS X 10.5 (Intel) has nothing close to a modern web browser. Thanks to the incredible persons at floodgap.com, 10.5 on PPC does in the wonderful TenFourFox, which (as its name implies) means OS X 10.4 has a more modern web browser than 10.6. Hell, Mac OS 9 has Classilla (progenitor of TenFourFox). In a perfect world I would use the 10.5 machine as the server for a newer, betterer everyday workstation, but that money doesnt exist. So out comes the Raspberry Pi.
Continue reading

Postfix PCRE TLD body check

This is used to reject spam e-mail containing a URL to the top level domains .date or .loan, and can of course be modified to include others. If you feel your users may ever have a legitimate need to be contacted about these domains it would be best to not use this.

Some familiarity with perl compatible regular expressions in postfix will be helpful.

/https?:\/\/([a-z,0-9,-]+\.){1,3}(date|loan)\// REJECT

This pattern matches both http and https protocols, and links containing from 1 to 3 subdomains of the TLD (http://3.2.example.com/ or https://example.com/ would match were .com the target).

Insert that line into your custom body checks file and no more spam du jour. Enjoy.

Parse e-mail for UPS tracking numbers

This AppleScript will parse the selected e-mail in Mail.app for UPS tracking numbers and will open the tracking page of the UPS website in your default browser.

This only looks at a single e-mail, but could be made to repeat through multiple selections.

tell application "Mail"
set _messages to selection as list
set input to content of item 1 of _messages
try
open location my parse_nums(input)
on error
display dialog "No UPS tracking info found."
end try
end tell

on parse_nums(input)
set input_new to ""
set output to ""
set input to every word of input
repeat with i in input
try
if first character of i is "1" and second character of i is "Z" then --Every UPS # I've seen starts with '1Z'
set input_new to input_new & i & "%0D%0A" as string --
URL encoded carriage return line feed needed for multiple entries.
end if
end try
end repeat
-- Now to remove the last set of new line characters.
repeat with c in characters 1 through ((count of characters of input_new) - 6) of input_new
set output to output & c
end repeat
set the_URL to "https://wwwapps.ups.com/WebTracking/track?track.x=Track&trackNums=" & output
return the_URL
end parse_nums

Set creation and modification date

This is to correct file times on photos that were imported from cameras with bad date settings or when they have been transferred to-and-fro and picked up the wrong data some where or after re-encoding high bit rate video to save a few GBs. [This does not alter the date atoms encoded in (most?) video files. ffmpeg can do that, however.]
Continue reading

OS X Server 5 Shenanigans

OS X Server 5 for OS X 10.10. and 10.11, while a significant improvement to Lion Server for OS X 10.7, still behaves oddly when mixing SSL and non-SSL requests. Whereas before it wanted every request redirected to the SSL pipe, now it will let you do either. It won’t, however, let you do both.

WordPress will try to do both. Why? I dunno. It should work, and did on plain Apache 2, but OS X Server 5 puts up a proxy to the WAN and serves from a different port. This is not presented upfront to the Server.app user, but is most likely in the docs. RTFM much? Ha-ha! No.

The affect this had on my WordPress install is instead of logging in being presented with a page that merely stated,

You don’t have permission to view this page.

Or some such equally helpful information. A little web searching turned up the answer. To overcome this the following can be added to wp-includes/http.php

/* Adding this BS for OS X Server 5 being a dick... */
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS']='on';
}

I saw a post on wordpress.net that said to put this into config.php, but that did not work for me. Neither did the mod_rewrite mumbo-jumbo in that thread and apparently it didn’t for the OP, either.

I admit being ignorant to what HTTP_X_FORWARDED_PROTO is, but it appears to be a HTTP header from an Apache mod Apple is running. Unique to them or something well known? I dunno. I don’t pretend to try to keep up with this stuff any longer. That’s why I went to WordPress; So I wouldn’t have to.

Number 1!

Number 1 in town for the National Bike Challenge.

20130701-085836.jpg
Of course this is first thing in the morning of the 1st day of the month and no one else had logged any miles, but still…