Pregunta

¿Hay allí una manera de comprobar una carpeta / archivo para cambios (incluye la adición de archivos, borrar archivos, los cambios en los archivos, ...). La 'acción de carpetas' en Automator sólo se está comprobando si los archivos se acaba de añadir.

¿Fue útil?

Solución

Se puede añadir una acción de "Ejecutar secuencia de comandos shell" con el comando:

find <directory> -newermm <reference_file>

Esto le dará a todos los archivos y directorios ubicados en <directory> que han cambiado desde el último cambio de <reference_file>. Sólo asegúrese de modificar el <reference_file> cada vez que se ejecuta el script de Automator.

también dan una mirada a la página del manual find (man find introducir en el terminal) para más opciones. Hallazgo es muy potente y más refinar su búsqueda suele ser una cuestión de un par de opciones adicionales. P.ej. para buscar sólo los directorios modificados después <reference_file>:

find <directory> -type d -newermm <reference_file>

Si la versión que se incluye con OSX no es suficiente, también puede probar la versión que viene con findutils (cerveza, macports etc.) que debe tener un poco más características.

Otros consejos

I don't know of a way to do this with Automator, but there is an app in the App Store called Folder Watch that may do what you're asking.

So last time I checked, Automater is using Applescript in the background to script your actions. Applescript does not have much depth to it. While it can get the list of files in a directory (and so therefore you could find out when something gets deleted), I don't believe it can calculate changes to a file.

What you really need to harness is file system notifications. And since that's a beast, I would take kraymer's advice and use launchd. It has hooks to execute anytime the contents of a folder is changed. Lingon (see also its outdated SourceForge page) is a great application for helping people jump into launchd. You can write your automator script/application to do whatever you were planning to do when your directory was modified and just have the launchd task call that.

You can check at an earlier answer of mine, but it sounds like you want

fs_usage -f filesys  

Launchd is not the way to go for file changes, fs_usage uses the underlying machine that powers spotlight.

EDIT: I'm utterly wrong here. Launchd has exactly that functionality required, ie: do something on a file or directory change.

You make a .plist file.

Scream "XML SUX FOR CONF FILES!" ( It really does. )

and you'll want to use one or both of the keys below in your launchd job.

WatchPaths <array of strings>
 This optional key causes the job to be started if any one of the listed
 paths are modified.

 QueueDirectories <array of strings>
 Much like the WatchPaths option, this key will watch the paths for modi-
 fications. The difference being that the job will only be started if the
 path is a directory and the directory is not empty.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a apple.stackexchange
scroll top