Join 3,512 readers in helping fund MetaFilter (Hide)


How can I automatically sync a file on a Mac?
July 2, 2006 8:32 PM   Subscribe

How do I automatically synchronize (via SFTP) an application data file at launch/exit of an application on a Mac?

I have some software that I run on multiple Macs that stores all of it's data in a single file hidden away in the Library somewhere. I'd like to automatically download this file, launch the application, and then automatically upload it again when I quit out of the application.

It would also be nice if I could archive it as a dated filename at the same time.
posted by sfluke20 to Technology (6 answers total)
 
Could this be done with some sort of subversion/CVS type solution? It seems that if you copied the file back to a central store every time it changed on a client PC you would be safe as long as that file was NOT being worked on by both locations at the same time. A running process that constantly looked at filesize or checksum on each client could determine when a sync was required. A cron script on the server side could automatically archive the file on every write. Anyone better with backups than I know of such a product?
posted by datacenter refugee at 9:28 PM on July 2, 2006


How do you mean "download"? If the file's "in the Library" then it's on your computer, and doesn't need to be downloaded. Or do you mean that you need to download the file from a remote location, put it in the Library, then run your app?
posted by AmbroseChapel at 9:41 PM on July 2, 2006


Keep all the user files on one machine running OS X Server.

With OS X Server you could serve up a home folder to multiple OS X clients.

The network home folder contains a Library folder with your preferences. When you run an application, so long as you are logged in, your preferences are kept on the central server.

Set up a 100 Mbit or Gigabit wired network between server and clients, or use the Mobility feature to synchronize changes to a home folder when a (wireless or remote) laptop is connected to the server.
posted by Mr. Six at 10:34 PM on July 2, 2006


Here's the most straightforward way I can think of. Write a little shell script that does these things, in order:

1) SFTP the file from your network location to the local location
2) Run the app: /path/to/YourApp.app/Contents/MacOS/YourApp
(the script won't go to the next step until the app quits)
3) SFTP the file from the local location to the network location
4) Copy/Move the local file to some special name with the date in it

Seriously, it would be four lines total, and should take somebody five minutes to write, given the details.

You'd have to always launch the app by running the script (which you could just do by double-clicking it in the Finder), instead of launching it normally...might be a problem for you, might not. It also is not particularly reliable if people might accidentally launch the normal app, or do this from different locations at the same time, or many other things... but again, you're choosing to do it this way, perhaps you can live with the fragility.
posted by xil at 11:48 PM on July 2, 2006


xil's got it! you can use the command-line osascript applescript handler to throw up dialogs that can warn you if stuff isn't working the way it should (no connection, whatever), or just tell you what's happening.

I would package it up by creating an applescript compiled as a .app that just runs the shell script. That way you can give it a real icon easily, and it'll work just like you expect in the Finder, the dock, and everywhere else.
posted by blasdelf at 12:58 AM on July 3, 2006


Thanks! I didn't know the trick about launching an application inside of Contents/MacOS/ which is what makes the shell script actually work!

Also thanks, blasdelf, for the tips about the applescript so I can have a standalone app.
posted by sfluke20 at 6:27 PM on July 3, 2006


« Older Any ideas on the value an unop...   |  Problem with starting PC: Star... Newer »
This thread is closed to new comments.