One of the challenges in my new career at Many Tricks is that Peter Maurer is located in Germany, while I'm here in the USA. I wanted to find a way to provide him with updated sales and expense reports without jumping through a lot of hoops. I decided on a private web page on our site, using Excel 2008's built-in "save as a web page" feature.
While Excel doesn't build the prettiest source HTML pages, the end result looks very much like the source page in Excel, which was fine for our needs. Excel even includes an automation feature that saves the web files each time you save the master worksheet. With that set up, I had an always-updated local copy of the financial report.
To automate putting this new page on the web, I turned to Folder Actions, and wrote a simple script to use scp to upload the files in my Sales Report folder. After attaching the script to the folder, I quickly discovered a key limitation: Folder Actions only 'see' new files being added to a folder; they don't seem to notice if you just update an existing file. So my slick script was useless, because the changed files weren't being updated.
The solution was a bit of brute force work: I modified the script that was uploading the files to also delete the files after upload. This is very rudimentary, as I don't do any testing to make sure the upload worked before deleting, but for our simple needs, it's good enough. My modified script (update.sh) is as follows:
#!/bin/bash scp /path/to/bizreport/index.html user@host:/path/to/bizreport/ scp -r /path/to/bizreport/index_files user@host:/path/to/bizreport/ rm /path/to/bizreport/index.html rm -r /path/to/bizreport/index.html/index_files(I have password-free ssh access set up to our web host, which allows the above work without requiring the password be stored in the script.) The Folder Action AppleScript looks like this:
on adding folder items to this_folder after receiving added_items do shell script "/path/to/bizreport/update.sh" end adding folder items toI'm sure there must be better ways to do this, but for a quick solution, it works quite well. The files created by Excel are quite small, so re-uploading everything doesn't take long at all. There's a brief "flash" to Finder when the Folder Action script triggers, but I'm quite happy with this basically fully automated solution.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20100330044914863