Issue with macro that moves files automatically [SOLVED]

I created this macro and when I test it on my laptop, everything works as expected, but I noticed that when I save files on my iPhone to iCloud, then I start getting error messages such as:

Action 16257671 failed: Get File Attributed failed to get attributes for /Users/dannywyatt/Library/Mobile Documents/com~apple~CloudDocs/_Inbox Global/.The illusion

Get File Attributed failed to get attributes for /Users/dannywyatt/Library/Mobile Documents/com~apple~CloudDocs/Downloads/.Am I missing

And if I'm not on my computer the whole day, when I come back I have a long list of macOS notifications. Why is it looking for a file with a dot in the beginning, when the file doesn't have it at all? And why is it behaving like this when I add a file from iPhone, but not on my Mac?

I just tested with a simple screenshot on iPhone and it worked as expected, so I don't understand what's causing the issue that sometimes it works, and sometimes it doesn't...

I don't think the size of the files is the issue, because one was 5.7MB and the other one just 680KB, and both got the same issue.

Move files and folders to Inbox Global automatically.kmmacros (23 KB)

Keyboard Maestro Export

The dot files you're seeing are, I believe, temporary files used when copying files. Those temporary files are also triggering your macro. You can try adding a semaphore lock at the start with a short timeout, so that it doesn't trigger again right away. That may work.

Or you may have to use a method to see when the file has been fully copied before proceeding. This involves a loop along the lines of:

Set CurrentSize to 0
Set NewSize to size of file being copied
Repeat Until NewSize = CurrentSize
  Pause some time
  Set CurrentSize to NewSize
  Set NewSize to size of file being copied
End Repeat

That's off the top of my head and might be wrong, but I think it's correct. Basically you need to check the file size over an interval, and only assume it's fully copied once the comparison is equal.

-rob.

1 Like

You could also try simply exiting your macro if the triggering file's name starts with . -- the assumption is that after it has completed syncing it'll be renamed to remove the leading period and that'll count as another added item and will trigger the macro again.

2 Likes

I see. It makes sense. So basically the dot files trigger the macro (trigger #1) and then I have that 10 second pause. Maybe while it's in the pause state, it finishes copying, converting the dot file to a normal file, creating a new trigger (trigger #2), but when it exits the pause state, it can't find the dot file anymore and that's the error I'm seeing, because I can indeed see that the final file is moved to the final destination as expected.

I've seen this mentioned before, but I have no idea what a semaphore lock is or what it does...

Isn't this doing the exact thing I'm doing with the macro? Or am I missing something?
My guess is what I mentioned before, that the dot file is gone while it's in pause, so it can't find it when I check its size again for the comparison action.

Yes, it seems like a good explanation of what's happening. I will definitely explore that idea of ignoring the dot file and see how it goes.

Thank you guys! At least I can see some light at the end of the tunnel

So I guess adding an IF THEN action would be enough, right?
image

As long as you add a comment to the "execute" section to remind your future self why you're doing nothing when the name starts with a . :wink:

2 Likes

Will do that. Thanks for the tip and for helping with this issue. It was driving me crazy!