Moving files added to Desktop to Folder gives 0k files

I need help moving dozens of files which are being saved to the Desktop into another existing folder.

When I do this with a simple folder trigger and test it with one file at a time, it works fine. When a dozen or more files are copied to the Desktop, when the files are moved, most arrive with 0k data.

I figured that the move macro was interfering with the saving of the file onto the desktop. So I tried using the shell command lsof to wait for inactivity using both folders' paths, but that didn't help. Then I tried adding a semaphore lock.

The combination of lsof and a semaphore lock was somewhat better. It only moved two files out of 20, but they came through with full data size. The other 18 files were still on the Desktop, and there were 18 macros still running.

If I turn off the lsof and just use the semaphore lock, I got several 0k files.

I'm really stumped. I think I need to wait for each file to be saved onto the Desktop before moving them. I just don't know how to accomplish it.

Any help appreciated.

Macro Image

There have been quite a few discussions about this on the KM Forum i.e. the Folder Trigger works fine with one file but can trip over itself with multiple files added all at once. I don't think a completely reliable solution has been found.

I use Keyboard Maestro for lots of things but for automating the moving of files I use the App Hazel. That would be my advice to you.

One thing that strikes me about the way you have set up your Macro - (if it works) it is going to automatically move any file added to the Desktop to a folder until you disable the Macro. Are you sure this won't be very annoying? Could you instead have a Macro that moves all/selected files on the Desktop to that folder giving you some control?

Are these files that are being downloaded? Just wondering if there is a more direct solution to putting these files where you want them.

1 Like

I wrote a macro group I call AppWatcher, which watches for the addition of an application to the Applications folder. The macro watches for the addition of a new app, then automatically makes an alias and asks me to categorize it.

I had a problem very similar to yours, in that the aliases often failed to get created properly. And that's because, even though I wasn't moving files myself, I wanted my macro to trigger on the adding of a file to a folder. But that file, the app, consists of thousands of individual files, and watching for changes (even with the "ignore impartial files" option checked) would just fail.

I needed a way to make my macro wait until the install was really done. What I came up with in the end was this:

EDIT: Looking at this code now, the order is probably a bit wrong. The delay should move up between the two variable setting points, duh. I'll fix that in the 1.3 version of the macro. It still works now, but the delay is basically meaningless. Move it if you use something like this :).

I use two variables that track the size of the file as seen in the du command in Terminal. I set the oldSize equal to the newSize, delay for 0.8 seconds, check the newSize, then repeat the loop until the two numbers are equal. The delay value could probably be shorter, but I wanted to make sure I gave the OS enough time to get some copying done between checks.

I also display a randomized progress bar, just so I can see that the macro is still waiting on things to finish copying.

If you download the linked macro group, this routine is in the AppWatchAdd macro. For your uses, you'd watch the entire Desktop folder instead of a particular file:

du -s /Users/your_user/Desktop | egrep -Eo '\d+\t'

Once that value stops changing, there's no more copying going on.

-rob.

I also recommend Hazel. KM is wonderful, but Hazel is tops at moving, renaming and many other finder/file functions.

1 Like

I used to use Hazel, so I updated it and reinstalled. In ten minutes everything is fixed and working perfectly. Thanks for the help!

1 Like