|
|
#1 |
|
Major Leaguer
Join Date: May 2002
Location: atl, ga, usa
Posts: 356
|
Automatically back up every file saved to this folder
Here's the problem, in case it inspires a better solution:
I use a program called Enigma to save settings for a musical instrument. If I want to delete one of the presets, just to unclutter the window's long list, the program actually deletes the saved file on the hard drive without warning. This has hurt me in the past. There's no way to get items out of that list except that single delete function, which zaps the saved file. The result I want: I want to delete presets, in Enigma, without losing their saved files. I keep forgetting that Enigma is the one app I have that does this to me. I need protection. I think a folder action might help, but my attempts fail. I tried making a script that does this:
... but that ran in a loop, as each copy it made re-triggered the folder action. I tried writing a script that duplicates the file to a different folder, but it's not working. Rather than ask you to debug my horrible script, I ask for a script, or ideas, from you. They're bound to be better than my cut&paste scripting. I really am not good at this sort of thing. All this is on a laptop that doesn't get hooked to the Time Machine drive very often, so attaching a Time Machine isn't an option. Ideas? A script that'll auto-backup any new file saved to a certain folder would be swell, I think, but I'm open to other ideas. |
|
|
|
|
|
#2 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
Making a Folder Action in Automator is very easy. You choose that template from Automator on launch (assuming it's 10.6 you're using). The one Automator action you're looking to use is Copy Finder Items, where you can change the destination folder.
If you're using 10.4 or 10.5, I can write you an AppleScript instead. Let us know how it goes! |
|
|
|
|
|
#3 |
|
Major Leaguer
Join Date: May 2002
Location: atl, ga, usa
Posts: 356
|
Ach, I should have mentioned I'm on 10.5
Ach, I should have mentioned I'm on 10.5.
Very kind offer. I would appreciate an Applescript so much. Thanks! |
|
|
|
|
|
#4 |
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,262
|
actually, the easiest way to do this is to set up a launchd job that runs rsync on the folder once or twice a day. take the following:
Code:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>user.rsyncbackup.folder</string> <key>ProgramArguments</key> <array> <string>rsync</string> <string>-a</string> <string>/Path/to/folderToBackup/</string> <string>/Path/to/newLocation/</string> </array> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>0</integer> <key>Minute</key> <integer>0</integer> </dict> </dict> </plist> I'd also drop a note to the developers about un-Mac-like behavior, but...
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW- Last edited by tw; 01-17-2011 at 01:25 AM. Reason: duplicate |
|
|
|
|
|
#5 |
|
Major Leaguer
Join Date: May 2002
Location: atl, ga, usa
Posts: 356
|
Thanks, tw, but once or twice a day won't solve the prob.
The prob is that the app deletes a file, but nothing about the interface tells me it's deleting a file, so it's too easy to forget and accidentally delete the work I just did. Once the file's deleted, it's gone (it doesn't even move the file to the Trash). No undo available. What I need is automatic protection from this. Like, to automatically copy every new file, within a minute or two of its creation. Later, when I once again realize I deleted a stinking file, I'll have a backup of it. Since we already have a script that alerts us when a new file is put into a folder, I hope we can use a script to copy that new file. I don't care where it goes as long as it gets copied soon after it's created or re-saved. The problem app, Enigma, is for editing settings in a few MIDI controllers I use. I use it on a laptop running OSX 10.5.8, and it's not hooked up to a Time Machine when I'm working with Enigma. I'll use this app maybe once in a couple of months; it's too easy to forget that only this app breaks some basic rules of interface design and permanently deletes an actual file, the only file, instead of removing an item from an on-screen list of settings (which is what a user would expect). I did tell the app developers about the prob, as did other users. They've known of the problem since 2006, if not earlier. Just not a priority for them, I guess. |
|
|
|
|
|
#6 |
|
MVP
Join Date: Dec 2009
Location: Pembroke, Ontario
Posts: 2,051
|
What you could do is set something to watch the path (tw can tell us how to do it the Unix way) and then rsync to another folder.
|
|
|
|
|
|
#7 |
|
Major Leaguer
Join Date: May 2002
Location: atl, ga, usa
Posts: 356
|
I see what you mean. That's along the lines I was thinking, at least the part about 'watch the path.' I put the classic "add - new item.scpt" on my Downloads, Applications and Public folders, on my desktop Mac, and I modified those to make the dialog box go away in 30 secs. That much, I could do.
What puzzles me is how to get the darn Applescript to copy the newly added file to some other location (or name). Really, just putting a copy in the same location, with " copy" added to its name, would be fine. It just isn't working when I try it. |
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Apr 2007
Posts: 4,262
|
to copy a file, use the Finder's duplicate command: Code:
tell application "Finder" set copyOfFile to duplicate file "Path:to:original" to "Path:to:copyfolder" with replacing set name of copyOfFile to newName -- omit this line if you want to use the same name end tell Code:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>user.rsyncbackup.folder</string> <key>ProgramArguments</key> <array> <string>rsync</string> <string>-a</string> <string>/Path/to/folderToBackup/</string> <string>/Path/to/newLocation/</string> </array> <key>WatchPaths</key> <array> <string>/Path/to/folderToBackup/</string> </array> </dict> </plist>
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW- |
|||||||||||||||||||||||
|
|
|
|
|
#9 |
|
Major Leaguer
Join Date: May 2002
Location: atl, ga, usa
Posts: 356
|
Thanks. I think a Folder Action, using Applescript, is preferable, because I have better chance of understanding it in the future when it breaks.
I have a question about Applescript: How can I write the snippet, below, so that it uses relative paths instead of hard-coded file paths? If possible, I'd rather it said something like "create a copy of every file placed here, and put it in this same folder" or maybe "create a copy of every file placed here, and put it in the "auto-backups" within this same folder". Here's the snippet: Code:
(* This is meant to be a Folder Action. This script should copy any file that appears in this folder. *) on adding folder items to ThisFolder after receiving added_items try tell application "Finder" set copyOfFile to duplicate added_items to "./autobackups" with replacing (* set name of copyOfFile to newName -- omit this line if you want to use the same name *) end tell end try end adding folder items to Last edited by osxpounder; 01-29-2011 at 06:52 PM. |
|
|
|
![]() |
| Tags |
| back up, back-up, delete, duplicate, folder actions |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|