Opening the wrong file

Hi all,

I have tried to create a macro that would allow me browse to a folder location using Alfred and then copy a new template google sheets file to that folder, and then finally open the newly created file. I'm having trouble with keyboard maestro opening the original file instead of the new copy.

This macro manages to copy the path to the folder to which I wish to move the new copy. It then saves it to the variable filepath.
It does then successfully copy the correct file to the correct location. However it will instead open the original file instead of the new copy. What am I missing here?

Any help or suggestions would be greatly appreciated.

The filepath variable appears to have a URL in it, which will not work as a file path.

Is the path you have selected in Alfred copied to the clipboard? As a path? Of a folder?

Is there a reason the Prompt for Folder action would not do what you want, or do you specifically want to browse for the folder with Alfred?

image

The filepath variable at the point I took the screenshot contains a URL because it just shows whatever is in the clipboard. If I had taken the screenshot right after running the macro it would have shown a file path. This is what it looks like right after I have used the macro.

That part of the macro does seem to function as intended which is proven by the fact that the macro does create the file in the correct file path, which is the file path that is copied at the start of the macro.

It's just in the last part, where I try to use the filepath variable again to open the new file that it instead opens the old file.

The Prompt for folder might work, but I want the ability to create files seamlessly while using Alfred to browse my files.

No, the left side of the arrow is the current variable value, the right side of the arrow is what it will set to (the current clipboard).

image

If you execute the first two actions, the last action displays as shown.

So the filepath variable had the URL in it at the time. It might be from elsewhere, from another macro, but it's odd to have a variable named filepath that has a URL.

Use the Log action to log the value you are opening.

You are correct. It was probably set to a URL because I was experimenting with the macro before I took the screen shot. I can understand why seeing the filepath variable assigned to a URL would raise red flags. I apologise for the confusion. But it has nothing to do with the issue I'm having with the macro.

When I am running it normally it does copy the file path from Alfred, which is clear because it does manage to use the variable to create the file in the correct folder. It's just the last part when I try to use the variable to open the file things go wrong and instead it opens the original file.

The solution was that I had to wait 5 seconds after the new file was created before I could try to open it, if it was opened faster the copy and the original would for some reason end up with the same url, even though they would still exist as different files with different file paths.

1 Like