Hi all. I am trying to copy a filename into the system clipboard. When one opens a folder and click on the down arrow twice, you end up at the position of the first file in the folder. When you hit the “return” key, the filename is highlighted. Then a Ctrl-C will copy this into the clipboard. How do I do this in keyboard maestro? I’m trying to upload a bunch of photos to my company’s server.
If you have a file selected in the Finder, then you can copy its path with:
- For Each Path in Finder Selection
- Set Clipboard to Text %Variable%Path%
(make sure the variable referenced in the For Each and the variable reference in the Set Clipboard are the same).
If you want just the name, you can use the Get File Attribute action to get the file name of the %Variable%Path%.
Groan. I’ll see if I can make some sense of this.
Thanks,
Jim.
What exactly do you need to do? Upload all files in a folder? Or perhaps you're going to select multiple files in a folder based on some criteria, then upload them?
Rather than use the clipboard, there might be a better way to automate the entire process, or at least a bigger part of it.
Let us know and we'll see what we can come up with.
Ok. I want to upload all the files in a folder “PHOTO” to the server via gmail. Each email with have the same address, but the subject line will be the filename. Tying “c” in gmail means start a new email, then tab to the subject field and insert the clipboard (Cmd-C) or filename (without the extension). Three more tabs will get you to the attached button which looks like a paperclip icon. Hitting returns opens up the folder PHOTO. Down arrow highlights the first file (alphabetical order) or the same file referenced in the Subject: line, Return initiates upload, pause upload complete, the Cmd-Return sends the email. Go back to folder. Two down arrows (to get past the “.DS Store” file, and delete the file just sent. Then copy the new first file name in the folder and go to gmail. I’m beginning to repeat myself.
I got all the actions down just like a robot, but not as fast. Maybe I can be a back-up for a factory assembly-line’s temporarily broken down robot? Somebody’s got to do that work.
OK, see if this helps you get started. There's two versions. Both of them repeat some action for each file. The difference is how they determine what files.
In the first version, you specify the folder in the macro, and it operates on all the .jpg files in that folder.
In the second version, you select one or more files in Finder, and it operates on all those files (if they're .jpg files - you could remove this condition if you don't need it).
Do Something with JPG files.kmmacros (6.7 KB)
PS: I didn’t fully test this, so if I made a mistake, either let me know, or see if you can figure it out. Either way is fine with me.
All the files will be jpg files, so I guess I can remove the test. But will the filename be in the system clipboard where I can recall it in gmail when I switch to safari?
Thanks.
Add a “Set Clipboard to Variable” action and specify “FileName” for the variable name. Do it right before the prompt.
I got it working but I did use the loop. I don’t trust it on automatic. Haha. Thanks, Dan. Thanks, Lewis.
"Trust, but verify", right?
Hi there,
I was hoping to use this like this:
I highlight a bunch of files
Trigger Macro
It copies each file name to the clipboard as a separate entry
Is this possible?
Definitely possible:
Copy Highlighted File Names to Clipboard.kmactions (984 Bytes)
That action will literally add each file name (including the extension) to the clipboard history as a separate entry, but it's also easy to set the clipboard to a list of every file name ready for pasting all in one go:
Thank you so much! I actually need them to be stored separately in my clipboard manager. I’m saving them to paste as filenames in my video-editing software.
I really appreciate you making the action, especially so fast.
Hmm. It seems to only save the last entry in my selection. I’m not sure if it’s because of my clipboard manager but this is one of the problems I ran into when I was trying to make it myself.
This macro is designed to work with Keyboard Maestro’s built-in clipboard history, so it’s no surprise that you’re only seeing the last file name in a different clipboard manager. Depending on what clipboard manager you’re using, there may be a way to have each file name added to its history as well, but you’ll need to tell us the name of your manager before we can even begin trying to figure that out. Alternatively, you could just use KM’s clipboard history for this task; that may be the easiest and fastest way to go in this case.
@gglick and @dduncombe,
One thing to be aware of when using the KM Clipboard History is that it will only store unique objects. So if you copy each of these:
one
two
three
one
You will find that "one" appears only once.
So, if this is a possibility, it may be better to store the list of names in a KM Variable, and then extract and paste as needed.