Zip droplet

This has been some hot garbage since I posted it. This is now actually not bad, but I can’t help but feel it’s clumsier than it could be. *meh*

Quick and dirty AppleScript droplet to zip files in the Finder.

-- http://strawhousepig.net/

-- This will not send files beginning with '.' (dot) to be zipped.

property def_loc : path to desktop
(*
If you're going to be sending zip archives to a location other than
a file-system domain (directories which the system has a 'nickname' for)
 I believe the above syntax would be:
	path to file "My HD:My Folder Daryl:My Other Folder Daryl:"
Or using POSIX style path
	path to POSIX file "/My HD/My Folder Daryl/My Other Folder Daryl/"
Although I am not sure about that. Another alternative would be to add an
if clause in the zip_it function to check for the "same" setting and then
use the container of item 1 of the files list "_it" as the default location.
*)

-- Not quite sure how to use this, in the AS routines or 'zip -x' or screw it and skip all files beginning with a dot?
--property no_can_zip : {".DS_Store", ".fseventsd", ".Spotlight-V100"}

on run
	tell application "Finder"
		set _it to selection as list
	end tell
	my zip_it(_it)
end run

on open _it
	zip_it(_it)
end open

on zip_it(_it)
	set _f to ""
	tell application "Finder" to set _dir to container of ((item 1 of _it) as alias)
	set my text item delimiters to {POSIX path of (_dir as alias)}
	repeat with i in _it
		if first character of name of (info for (i as alias)) is not "." then
			set _f to _f & " " & quoted form of text item 2 of (POSIX path of (i as alias))
		end if
	end repeat
	set the_c to count of _it
	if the_c > 1 then
		set z_name to (displayed name of (info for (item 1 of _it as alias))) & " + " & (the_c - 1) & " items.zip"
	else
		set z_name to (displayed name of (info for (item 1 of _it as alias))) & ".zip"
	end if
	set _z to (choose file name with prompt (the_c as string) & " item(s) to zip." default name z_name default location (_dir as alias))
	do shell script "cd " & quoted form of POSIX path of (_dir as alias) & " && zip  -ry " & quoted form of POSIX path of _z & _f
end zip_it

Parsing e-mail for info

[UPDATE] Added a version that works on OS X 10.4 to the bottom of this post. Does some different logging and is tighter, so I’ll have to go back to the original and update again.

This was done earlier, but I have since had to change it to match changes in the incoming data. Some of which is a big mystery. In particular a new line character that is input as the “line separator” Unicode character. It would end up in the clipboard as line feed, so I just started plugging in white space character id’s until one hit the mark. Lucky me.

Continue reading

Convert PDF to grayscale using GhostScript

[UPDATE] Huge caveat! While this is really meant to deal with RGB documents or objects, it does also convert CMYK and spot colors to grayscale. Unfortunately spot colors remain as separate plates that retain their name. This results in them being printed in color though on screen they appear gray. At least the colors (Pantone) and printer I tested on took spot channels and ripped them according to what they are named. If your printer does not have it’s own rendering library that matches your spot color names then I’m guessing they will print as grayscale.

It is possible to rasterize the art, which results in a pure grayscale, but you need such a high resolution even a simple business card with type and line art increases in size at least 30 times. I knew this was all too easy…

This script / app / droplet will convert a PDF or PostScript (.ps) document from whatever colorspace it lives in to grayscale. Has not been thoroughly tested. I mean, I ran it against a couple of files. One to work out the gs command, the other to test if it actually made a grayscale duplicate. That file was generated by MS Word so was of course RGB. The converted document was in fact true grayscale. I would say it converted to what you would get if you used a gray gamma 2.2 profile.

Continue reading

AppleTalk in the current year

If you’re anything like me and you have to print to an old AppleTalk printer, server, or RIP, -my condolences- keeping up-to-date and bridging that old connection becomes more difficult every decade. You are left with two choices; Keep an oldish Mac on hand capable of running Mac OS X 10.5 or earlier (a Power PC (PPC) is best in order to run the only browser using a modern cipher suite, TenFourFox [unfortunately development has ceased 🙁 ] from the brilliant and beautiful people at floodgap.com) or you can run an OS built on GNU+Linux, even as virtual machine, and have a fully modern desktop OS. Although in a VM a headless console will have a smaller footprint.

Continue reading

Convert PDF to JPEG using (old version of) Acrobat

This script will use Acrobat’s built in conversion settings (set in Acrobat’s preferences) to convert an open PDF to a new JPEG file and place that file in the folder of said PDF. If a file with the same name (including extension) exists it will prompt for a new name, at which point you may enter a new name or keep it the same and replace the old file.

Not allowing Acrobat to name the new file because, on Macintosh, Acrobat has a ridiculously low character limit when auto-generating a file.

Has not been tested with multi-page PDF’s, but I do not think it will handle them correctly [it does not]. Acrobat will do it, but the extra file shuffling will not. Also unknown if having a window (document) minimized will cause any shenanigans.

Also note this is written for Acrobat 7. Why? Because old hardware needs old software.

[UPDATE] Changed to allow multiple selections.

tell application "Adobe Acrobat 7.0 Professional"
try
set _docs to name of every document
if (count of _docs) is greater than 1 then
set _docs to (choose from list _docs with prompt "Select file(s) to convert:" with multiple selections allowed) as list
end if
repeat with i in _docs
set _doc to (every document whose name is i)
set _path to file alias of item 1 of _doc
set _temp to (path to temporary items folder as text) & "acrobat_tmp_jpg"
save item 1 of _doc to file _temp using conversion "com.adobe.acrobat.jpeg"
tell application "Finder"
set _name to (text items 1 thru -5 of i) & ".jpg"
set _proof to ((container of file _path) as text) & _name
if (exists _proof) then
set _name to text returned of (display dialog "File '" & _name & "' already exists. Please enter a new name (or leave the same to replace):" default answer _name as text)
set _proof to ((container of file _path) as text) & _name
end if
do shell script "mv " & quoted form of POSIX path of _temp & " " & quoted form of POSIX path of _proof
reveal file _proof
end tell
end repeat
end try
end tell

Speaking against the media narrative of motor vehicle collisions

As a once/sometime/hopefully again vehicular cyclist, a father, and a driver who tries to change my own attitude toward driving and motor vehicles, I consider myself part of the Crash Not Accident crowd. And this is my comment/rant on a recent article about a “truck getting into an accident with a pedestrian” (to paraphrase it).

Genericized and placed here for possible future use. This may be expanded on at some point.

Drivers don’t get cited because society gives us a pass. That’s starting to change but we need publications like this one to get on board. When describing a collision involving a motor vehicle do not attribute it to the vehicle. The truck didn’t hit the pedestrian, the driver did.

Also, drop the term “accident.” When an outside force is not involved these crashes and wrecks are *never* an accident. Faulty manufacturing, poor maintenance, and especially lack of due care while driving are all 100% preventable by a person making a better choice. The smoldering wreckage and broken bodies of a motor vehicle collision are consequences, not accidents.

Driving is by far the most dangerous thing most people will ever do. It’s past time to (once again) see it for what it is. Maybe then tens of thousands of people wouldn’t be killed year after year after year.

Video re-encode script

The purpose of this long, arduous venture was to find a way to simply reduce the size of video files recorded with a Canon ELPH 330 HS digicam. This camera, and surely others, records 720p, 30fps video at a bitrate of 24Mbps, which is at least twice as much as should be necessary. Remember this is a consumer level point-&-shoot whose main draws were: 10x optical zoom; pocketable. This high bitrate results in a 6 minute video being over 1GB. Too much.
Continue reading

Copy video create date from original file

This is the companion script for: Video re-encode script

It uses exiftool to copy the video date atom(s) and setfile (is or was included with Apple’s Developer Tools) to change the file system dates. It will more than likely throw exiftool “File not found” errors and I’m not quite sure why. It has never failed to actually work despite this in my experience, however be very careful to not use this on your original source videos.

Hopefully the settings and prompts make sense.

(* http://strawhousepig.net/

This uses Apple's command line developer tools command 'setfile' to set the filesytem dates.

https://developer.apple.com/download/more/

I believe an Apple Developer account is required for that, but I am not sure.

Uses 'exiftool' to set track date atoms.

https://www.sno.phy.queensu.ca/~phil/exiftool/

*)

-- Set to 'false' to omit initial dialog prompts. Does not affect final confirmation prompt.
property prompt_me : true

-- UTC timezone. Leave blank ("") to not use the timezone setting.
property tzone : "-8:00"

on run
do_it(false)
end run

on do_it(redo)
repeat
if tzone is not "" then set tzone to "-timezone=\"" & tzone & "\" " -- There is a trailing space here.
if prompt_me is true then
if button returned of (display dialog "Choose a TARGET file to set creation and modification dates of.") is "OK" then
set newfile to choose file with prompt "Select TARGET file to set creation and modified dates of:"
end if
else
set newfile to choose file with prompt "Select TARGET file to set creation and modified dates of:"
end if

set filepath to newfile as string
if prompt_me is true then
if button returned of (display dialog "Choose a SOURCE file to *get* creation and modification dates from.") is "OK" then
set oldfile to choose file with prompt "Select SOURCE file to get dates from: " & filepath
end if
else
set oldfile to choose file with prompt "Select SOURCE file to get dates from: " & filepath
end if
set newfilename to name of (info for of newfile)
if newfilename is not (name of (info for of oldfile)) then
set warn_button to button returned of (display alert "File names do not match. Proceed?" as warning buttons {"Cancel", "Start Over", "Proceed"})
if warn_button is "Cancel" then
return
else
if warn_button is "Start Over" then
set redo to true
exit repeat
end if
end if
end if
tell application "System Events" to set [c_date, m_date] to [creation date of oldfile, modification date of oldfile]
set [p_date_c, p_date_m] to [c_date, m_date] -- Saving "pretty" date for dialog prompt.
set c_date to ((month of c_date as integer) & "/" & day of c_date & "/" & year of c_date & " " & hours of c_date & ":" & minutes of c_date & ":" & seconds of c_date) as string
log c_date
set m_date to ((month of m_date as integer) & "/" & day of m_date & "/" & year of m_date & " " & hours of m_date & ":" & minutes of m_date & ":" & seconds of m_date) as string
log m_date
if button returned of (display dialog "This will set the creation and modification dates of file " & filepath & " to:" & return & return & p_date_c & return & p_date_m & return & return & "Proceed?") is "OK" then
try
-- Have to include full path to exiftool binary because AppleScript uses the Bourne shell which doesn't have /usr/local/bin in its path? *rolls eyes*
do shell script "/usr/local/bin/exiftool " & tzone & "-*date=\"`/usr/local/bin/exiftool -time:CreateDate " & quoted form of POSIX path of oldfile & "`\" -wm w " & quoted form of POSIX path of newfile
on error theErr
-- Will throw a "File not found" error if this takes over a certain amount of time. rm must be running faster than exiftool can finish?
display dialog "The 'exiftool' command said: " & theErr
end try
delay 1
try
-- Ready for this, exiftool adds "_original" to the end of the file it's going to modify tags/atoms of. This is still 'newfile' but with a new name.
-- If we manually add "_original" to 'newfile' rm will throw an error looking for newfile_original_original... Wha?
do shell script "rm " & quoted form of POSIX path of newfile
on error theErr
display dialog "The 'rm' command said: " & theErr
end try
delay 1
try
-- Ready again? The original path to 'newfile' is valid again for this... Wha??
do shell script "setfile -d '" & c_date & "' -m '" & m_date & "' " & quoted form of POSIX path of newfile
on error theErr
display dialog "The 'setfile' command said: " & theErr
end try
end if
exit repeat
end repeat
if redo then do_it(false)
end do_it

Cyclists behaving badly? Riding group won’t share the road [Because there isn’t room to]- YouTube

This “news” piece is a disgusting example of stoking motorist elitism and violent attitudes. I feel a few things need to be made straight:

  • There is not room for a car and a bicycle to safely share those lanes side-by-side. Repeat that.
  • Taking the lane is done to cause a motorist to not try to squeeze past with their multiple ton metal box in a lane that does not accommodate that safely. Slowing down and waiting for a safe opportunity to pass will take, what? 10 seconds? 20? 30 or 60? How many minutes would it take for you to be comfortable with someone risking the rest of your life and your family’s lives without you? I’m guessing there isn’t any number at which anyone would be, so don’t risk that of anyone else for the same. Just slow down, be patient and hope others treat you with at least that basic amount of human decency.
  • By riding abreast a large group significantly reduces its length and likewise the time and distance it takes to overtake them. Imagine trying to pass a single file line of 20 bicycles that must ride in the center of the lane due to lack of safe space. That part of British Columbia’s Motor Vehicle Act should be changed for everyone’s benefit.
  • No one stops at stop signs. Whether people walk, ride, or drive people go right on through whenever they feel they have the chance. This is not a cyclist thing, it’s a people thing. The only difference is when a motorist does it it is dangerous for everyone around them. Every time. This article does a good job of introducing a study from the University of South Florida which reflects this point.
  • On that point, imagine how happy the average angry motorists would be to have to sit and wait for 20 bicycles in front of them to each come to the complete stop motorists only demand of cyclists? Yet it will only take a few seconds for the whole group to follow the leader. There’s no need to imagine that, though. In San Francisco, people on bikes do just that occasionally.

I hope the shortsighted producer(s) at CTV who made this video trash is ashamed of the hateful, violent comments it’s drawn from divers. Because I guarantee someone they love and who means the world to them, or someone that person loves, will face the violent hatred of a motorist someday for the simple act of riding a bicycle. Same goes for those commenters.

All it takes is a little empathy and considerate thought about the way things work to see you owe the world around you the utmost care while operating a machine as dangerous as a motor vehicle and that, no, a motor vehicle does *not* imbue you with privilege above others.