Recently in Computers and Information Systems Category

Automating Mac OS X

| | Comments () | Digg This | Facebook

I've been having fun with Apple's new Snow Leopard, the latest upgrade of their OS X operating system.

One of the big improvements they've made is in simplifying the way that users can easily automate repetitive tasks.

One of the minor pains in my butt has been the online statements from bank accounts and other companies. They download to the hard drive with an odd name, like STATEMENT.PDF; then I have to manually rename them and move them into the folder where I keep them.

Sounds like a great prospect for automation.

After some experimentation, I decided that a shell script attached to a Folder Action was the way to go.

My script looks for certain file names in the Downloads directory and automatically renames them to include today's date and the name of the company. For example, when it sees a file named JPMCStatement.pdf it will move it into the ${HOME}/Documents/BillingStatements/AmazonVisa folder and change its name to AmazonVisa-2009-08-30.pdf.

And for good measure, it pops open the folder in the Finder with the new file highlighted.

Here's what I did.

Start up Automator and select Folder Action from its opening screen.

Select the folder that you want to monitor from the Choose folder popup.

Now drag a Run Shell Script action (under Library Utilities) and drop it as the first item in your workflow. Set it to Pass input as arguments.

Copy and paste the following code into that action, making the changes needed to customize it for your needs. (I tried to make it fairly easy to modify by editing the values of variables and adding more statements to the case structure, but it is a shell script after all.) Actually you are probably better off by creating a shell script file and testing it in the terminal first; just uncomment those echo statements to test.

DATE=`date "+%Y-%m-%d"`
SRC_DIR="${HOME}/Downloads/"
DEST_DIR="${HOME}/Documents/BillingStatements/"
TARGET_FILE="none"
BASENAME=`basename ${1}`
ORG_FILE_NAME=${1}

case ${BASENAME}
in
  "JPMCStatement.pdf")           TARGET_FILE="AmazonVisa";;
  "processStmtExpressAction.do") TARGET_FILE="Dish";;
  "STATEMENT.PDF")               TARGET_FILE="TDBank";;
#Add more cases before the esac
esac

TARGET_DIR="${DEST_DIR}${TARGET_FILE}/"

#echo ${TARGET_FILE}
#echo "${TARGET_FILE}-${DATE}.pdf"
#echo ${ORG_FILE_NAME}
#exit

if test ${TARGET_FILE} != "none"  
  then
  echo "Original file: ${ORG_FILE_NAME}" >>${SRC_DIR}my.log
  NEW_FILE_PATH_NAME="${TARGET_DIR}${TARGET_FILE}-${DATE}.pdf"
  mv ${ORG_FILE_NAME} ${NEW_FILE_PATH_NAME} 2>>${SRC_DIR}my.log
  echo "Processed file: ${NEW_FILE_PATH_NAME}" >>${SRC_DIR}my.log
  echo "${NEW_FILE_PATH_NAME}"
fi

Now drag a Reveal Finder Items action (under Library Files and Folders) as the next item in your workflow. Save it, and with a little bit of testing, you should be good to go!

Then again, it is a shell script...

Automator example.png

ab63_hacked_flash_drive.jpg

Via Schneier's security blog comes word of this nifty device.

It's a 2 Gig USB drive designed to look like a frayed cable.

So if the border police search your bags, they'll likely overlook it because it appears so innocuous.

Love it!

The previous post reminded me of an incident that happened over 20 years ago.

In those days I was working in a place called the Defense Personnel Support Center (or DPSC) in the Subsistence directorate, which was responsible for supplying our warfighters with (what else?) their food. This involved everything from fresh fruits and vegetables to something known as MREs.

That stands for "Meal, Ready-to-Eat", which probably sets a record for fitting three lies into four words. The military had recently replaced its traditional canned rations with MREs, and a problem had developed.

There was no way to track the original ingredients from the supplier to the finished end item, so when a problem was discovered, an entire supply of end items had to be recalled, rather than just those items which had come from the offending source.

A co-worker (call him "Joe") developed a tracking system (written in dBase III) for deployment at the manufacturers' plants, and I pitched in with some utilities to add a few capabilities that dBase lacked. We tested as thoroughly as we could, and then sent it off the the contractors.

But there was a problem: when the contractors tried to run the program, it crashed their PCs.

dos_environment.jpg

This was in the days of DOS (remember DOS?), and to make a long story short it turned out there was a nasty bug in my code that caused my program to overwrite a part of memory that rightfully belonged to DOS.

Why hadn't we noticed the problem? As it happened, the area of memory that it overwrote was called the Environment, which was used to store (what else?) environment strings. On all of our PCs, we had the Environment filled up with all sort of assorted strings, so when my program invaded that area, there was no problem because the Environment space was large enough to handle the invasion.

But the PCs at the contractor's plants didn't use the Environment at all, so when that area of memory was overwritten, it crashed their systems.

Fixing the program was easy, but it would take several days to get the fix out to the contractors, so we gave them a temporary workaround:

We suggested that they add a string to their Environment when they started up their PCs. I don't remember exactly what we suggested, but it was something like "SET DPSC=A_FINE_BUNCH_OF_FELLOWS".

organic_tomatoes.jpg

Here's the short version.

The food industry spent millions of dollars to lobby the Bush administration to gut the record-keeping regulations that the FDA wanted to make it easier to track foods from farm to consumer.

Now here's the thing. If the original regulations had been in place, they would have saved the food industry far more than it would have incurred to follow them, because the recent salmonella scare could have been resolved more quickly.

From the article:

One of the worst outbreaks of foodborne illness in the U.S. is teaching the food industry the truth of the adage, "Be careful what you wish for because you might get it."

The industry pressured the Bush administration years ago to limit the paperwork companies would have to keep to help U.S. health investigators quickly trace produce that sickens consumers, according to interviews and government reports reviewed by The Associated Press.

The White House also killed a plan to require the industry to maintain electronic tracking records that could be reviewed easily during a crisis to search for an outbreak's source. Companies complained the proposals were too burdensome and costly, and warned they could disrupt the availability of consumers' favorite foods.

Here is the full story.

Now my question is this: Is this a good example for those who argue that government can never work and everything, including oversight, should be left to private industry? Or is it an example of why we need the government to oversee private industry?

Discuss.

Reading List

About this Archive

This page is an archive of recent entries in the Computers and Information Systems category.

Find recent content on the main index or look in the archives to find all content.

Older content can be found at the original Compassionate Curmudgeon site.