Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Force Folder Actions to notice changed files System
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 to
I'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.

This general approach should work for other situations where you want a Folder Action to trigger on changed files in addition to newly-added files. As a variation, it should also work if you used a mv to move the files somewhere else first, then mv them back. You could also do this all in Automator or Script Editor, but as I had the shell script already in place, I just kept it there.

If there are more elegant ways to accomplish this, I'd be interested in any alternatives. (I didn't want to use Transmit and its Automator actions as I didn't want Transmit to load every time I saved my Excel file.)
    •    
  • Currently 2.71 / 5
  You rated: 4 / 5 (17 votes cast)
 
[11,740 views]  

Force Folder Actions to notice changed files | 21 comments | Create New Account
Click here to return to the 'Force Folder Actions to notice changed files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Force Folder Actions to notice changed files
Authored by: wheeles on Mar 30, '10 07:59:10AM
Alternately, you could have just used Dropbox and shared a folder with him where you kept all the documents that you both need up to date. Dropbox is ideal for such things and no messing about with shell scripts required.

[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: Scott Weidig on Mar 30, '10 07:59:50AM

Rob,

While your process works and Peter can view the sales information, he can't really interact with the data or from what it sounds like run reports over time, etc.

I'd like to suggest that you use an online service like Google Docs or really I'd suggest Zoho (zoho.com) to leverage an online spreadsheet that you can share, both be in at the same time, both have access to add or manipulate data (if you want that) and both be able to leverage the charting and reporting tools like pivot tables etc.

Not only will it be a lot cleaner, and you would not have to create an automated script, you can also take sections of the spreadsheets, documents, presentation, etc. And embed them into websites or other tools to leverage your data further... Also if someone else needs access to view or participate in the sheet, you simply set up the permissions and share the sheet with them, and revoke that access later if necessary.

Hope this helps,

Scott



[ Reply to This | # ]
Dropbox?
Authored by: Nem on Mar 30, '10 08:21:50AM

Just thinking that maybe Dropbox could be used here instead.

---
Nem W. Schlecht
http://geekmuse.net/



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: mark hunte on Mar 30, '10 09:03:40AM

I can not check this out at the mo.. but doesn't Numbers in iWorks have a share file feature.

---
mh



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: robg on Mar 30, '10 09:20:11AM

As soon as Apple makes Numbers do what Excel can do, I'll start using it. Until then, it's Excel. (Two examples that make it impossible for me to use Numbers: no formulas in conditional formatting, and no array formulas.)

-rob.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: robg on Mar 30, '10 09:25:50AM

For those suggesting Drop Box, I have it and we use it for a number of things. But in this case, I wanted the file to be web-accessible (for a number of reasons). It also doesn't make any sense for Peter to be in the actual Excel file, so I don't want to put that in Dropbox.

As for Google Docs (and Numbers, for that matter), its spreadsheet isn't advanced enough to do the manipulation required on the data file we get from our online sales cart provider.

The idea was to generate an actual nice looking sales report, something that doesn't require interaction, but gives a snapshot look at the business. For that, Excel's web page output is ideal. It was just getting the form online that was a bit tricky.

But the more general hint here is that you can force Folder Actions to read new files in a folder by removing them, and then re-adding them. Common sense, I know, but it took me a while before I thought to actually try it.

-rob.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: jeffner76 on Mar 30, '10 09:31:13AM

Dropbox does have the ability to be web accessible. You can either access a folder directly through the dropbox folder on your computer or by logging into dropbox.com. There are a couple of different ways you could share access to Dropbox - (1) create one account, share the login information between two computers. (2) Create an account for each user then "share" the folder with the excel doc you want multiple people to have access. We are using this at my company (two users, 2 accounts, shared access to certain folders) and it's working very well. I've also gotten my family members on it so that we don't have to email files back and forth and keep up with revisions. Good luck!



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: wheeles on Mar 30, '10 11:06:44AM

You can always save your html file to your Dropbox public folder. It can then be viewed online as a webpage by those who know its address.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: scotty321 on Mar 30, '10 09:31:35AM

Why not create a simple database with FileMaker Pro, and then use its brilliant & flawless "instant web publishing" feature? Then, you can both edit the data in real time using the web.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: robg on Mar 30, '10 03:15:09PM

Peter doesn't need to edit the data, and Filemaker can't manipulate the data in the way that I need to.

-rob.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: TonyT on Mar 30, '10 10:17:32AM

launchd can do what you want.
Just have it watch if the file is changed and then run a script ("WatchPaths"). If you need it to also act on any new files added, have it 'watch' the directory (a directory is, after all, a file and it's date will be modified if a file is added to it).

Don't try to act if a file is added to the directory ("QueueDirectories"), as this has the same limitation as Folder Actions (i.e. the folder has to be cleared after the the script is run)

One of my favorite apps, Lingon, makes writing the launchd playlist easy.

Edited on Mar 30, '10 10:32:49AM by TonyT



[ Reply to This | # ]
Improvements
Authored by: lullabud on Mar 30, '10 10:53:40AM

One way to improve this would be to use "rsync -aPq srcfiles desthost:/path/on/server" instead of using two scp commands. This will update the whole tree in one command. You could even just put that in cron and let it run ever 5 minutes or however frequently and skip the folder action, so long as you don't need that instantaneous upload.

Another way to do this without the folder action would be through launchd, which would keep the Finder from flashing. (see this hint - http://www.macosxhints.com/article.php?story=20080423051638134 )

Using launchctl also lets you do the whole thing in a shell script rather than gluing shell scripts into applescript.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: foilpan on Mar 30, '10 11:06:43AM

why are you using a spreadsheet for such things in the first place? wouldn't a hosted or in-house web app be more flexible? any time i see people syncing data back and forth like this for collaboration, it screams "web app" to me.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: TonyT on Mar 30, '10 01:16:26PM

...but its not 'back and forth', its only forth.
Why 'force' the reader of the info to do anything more than 'read' if all he wants to do is read!



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: robg on Mar 30, '10 03:13:18PM

1) It's not collaboration, it's a report. It's my job to create it and work with it; Peter just needs to see it.

2) No web app I've seen can match Excel's abilities. To pull the numbers together, I'm using formulas that don't exist in Google Docs.

-rob.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: luomat on Mar 30, '10 08:03:18PM

You can share the actual Excel file over Dropbox without putting it in your Public folder, which will alleviate the need for any conversation while keeping it private.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: esbenab on Mar 31, '10 01:18:41AM

I must recommend Launchd(eamon), using Lingon.app it's easy to set up that the folder is watched and subsequently a script run when there are changes.

This can be done as low as file level on the individual files.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: TonyT on Mar 31, '10 10:10:21AM

I also suggested launchd. Maybe we should submit as a 'hint' as is seems that Rob is ignoring this suggestion even though he said that he would be interested in a more elegant ways to accomplish this.

Tony



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: robg on Jun 02, '10 05:16:27AM

Sorry, not intentionally ignoring -- just got too busy with new job and old job transition to keep following this thread. I will look into <tt>launchd</tt> to replace my script.

Also, since I posted this, we have switched to FileMaker Pro for tracking the data, and then I use a FMPro script to dump data files that Excel then uses to create the sales report. It's the best of both worlds; I have FMPro's data management capabilities, and Excel's reporting and number crunching abilities.

-rob.



[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: hariya on Mar 31, '10 01:20:13AM
Why not use Hazel? I think your need fits Hazel's capabilities perfectly.

[ Reply to This | # ]
Force Folder Actions to notice changed files
Authored by: glusk on Mar 31, '10 09:00:11PM

Except for possibly using rsync instead of scp (not sure if there's a different end result for what you're doing) it seems like this was the simplest method to let people view a web version of your spreadsheet. I find it annoying to have someone email me a spreadsheet or invite me to collaborate (in Google Docs) when I just want to look at the data. That's what PDF or HTML is for. And your script seems to keep things pretty simple.



[ Reply to This | # ]