Page 1 of 1

"discover" deleted files?

PostPosted: Mon Jun 29, 2009 4:42 am
by halvor
I suspect the answer is no, but should try to ask : -) is there any way to make a rule that would discover that a file has been deleted?

something like "if previously matched file is not there any more" : do action .. (including pass me the reference theFile or $1 to where it used to be)

Thanks : -)

Re: "discover" deleted files?

PostPosted: Mon Jun 29, 2009 11:48 am
by a_freyer
First, this post might get more traffic if it were filed properly in Support. Perhaps a mod could move this topic to the right forum.

Second is probably not the answer you wanted to hear: No.

In order to maintain a list of files that were within a folder, Hazel would have to maintain a database of some kind. Once a file is moved from a directory, there isn't any remnant file left behind (that would sort of defeat the purpose of moving the file :) ). Hazel would have to maintain a very large database for this to be implemented - and I doubt that its a feature thats in high demand.

You could try and monitor the trash and compare that with the last matched date - maybe.

Re: "discover" deleted files?

PostPosted: Tue Jun 30, 2009 12:07 pm
by halvor
Thanks for reply.

answer was expected : -)

(My use is that I have an archive of tif files, which stays in sync with an archive of jpg files. If files are added or edited in tif archive, a copy is sent over to the jpg archive and then converted to a jpg (with overwrite). Have currently a script that will regularly check if there is a jpg without a corresponding tif file and if so, delete the jpg. So things functions, but the whole setup would have been simpler and possibly more stable if it all could have been done from hazel. I´ll wait for the industrial version of hazel for that function : -)

Re: "discover" deleted files?

PostPosted: Tue Jun 30, 2009 2:17 pm
by Mr_Noodle
This is already in the feature database though I'm still unsure how it would work. For one, any actions would have no file to operate on. It seems in your case you want a correlation from one file to a different one. It would take a bit of thought and work to do this in any general fashion.

Also, there would be issues with whether a file was actually deleted or just moved somewhere else. I can probably track the file if Hazel moves it itself or if the file is moved to another folder on the same disk. When it crosses disk boundaries, though, there's a good chance Hazel will not be able to differentiate between the file being deleted and it being moved away.

But don't let this discourage you from asking. The more examples you can bring up helps to give me an idea of how something like this would work.

Re: "discover" deleted files?

PostPosted: Wed Jul 01, 2009 8:29 am
by halvor
...some loose thoughts, I really do not know enough about it but the word apple events comes to mind ... might be an option to at least discover that something is happening in a watched folder ... then check if a file has disappeared

a second idea is to "simply" link hazel to cron, or add a timed event option to the rules (might be useful for other purposes), sort of, every so often check for missing files with a database.. (a plug-in module for hazel ? : -) for me, a simple solution is "find PATH to Folder > dir.txt" this produce a list with paths to everything in that folder (with 40.000 files this is about 200 kb) one can then do this at intervals and use "diff" to compare if anything has changed since last "find". Not a hazel solution, but the concept might work.

in my specific case, hazel do not need to do any action on the file that was deleted, but I need to know which file it was with path. I then, with a script, replace head of path and with sed change extension from tif to jpg, and then delete the jpg file, this is essentially a synchronize function but as it consist of different kind of files I can not use a normal sync program..

if a file is moved hazel simply discovers this as a new file (and then with an applescript copies the file across) (in other words, I do not need to track the file)

a bit messy to explain all this here, I will try to write a manual for this archive soon, will mail it to you once done. For me, hazel in combination with zenphoto and some scripting has produced roughly the same functionality as a professional archiving program, (which would have cost about 10.000 dollar to set up ... : -)

Re: "discover" deleted files?

PostPosted: Wed Jul 01, 2009 1:10 pm
by a_freyer
If you're just using this for photo archiving, have you considered monitoring the trash? Perhaps something like this:

    (1) In folder ~/.trash/ if file matches (Photo Name).jpg then run script : rm "path/to/tif/directory/(Photo Name).tif"
    (2) In folder ~/.trash/ if file matches (Photo Name).tif then run script : rm "path/to/jpeg/directory/(Photo Name).jpg"
    (3) Growl Alert...

This might assume that you're naming your photos in a standard way, or that all of the photos on your computer are stored with this archiving system.

Re: "discover" deleted files?

PostPosted: Wed Jul 01, 2009 3:22 pm
by halvor
one moment , thinking : -) ... that might be made to work ...

in my case there will be multiple files with same name in different sub directories, not entirely ideal, but have not had time to clean up.

So:

(tiff folder is master folder, jpg folder should stay in sync with tif folder. Zenphoto is on top of jpg folder and gives browsing and search functionality to archive over intranet, while main tif archive is kept at a "safe" distance from users : -)

First: File added to trash is trigger, (can hazel be made to watch the trash folder?)

in pseudo code : -)

get name of theFile minus extension

find "name of theFile minus extension" in tifDir | sed "replace head of tifDirPath with head of jpgDirPath" > tif.txt
find "name of theFile minus extension" in jpgDir > jpg.txt

compare (diff) tif.txt with jpg.txt grep the result (minus garbage from diff) sed on .jpg again in end and rm in front >> rm.sh
(to prepared script)

./rm.sh
(delete file(s))

this would not work over a network because file do not go to trash when deleted that way. (currently in my case three people has read&write rights in archive, suppose I should reduce that to reading rights & send an email if you want a file removed : -) (but it is a lot faster to delete a file yourself than to send an email about it...human factor)

In general terms, all one need is a trigger, the rest can be adapted. Adding files to trash can work as a trigger, but then that would also trigger every time anything is deleted. For me that would be harmless, if I delete a file that did not come from the archive the script would run, but without results because tifDir = jpgDir, a bit clumsy, but mostly harmless : -)