I want to move all files containing the following text in their filenames, “Screen Shot” to another directory.
So in other words, a wildcard to select all files that have “Screen Shot” in their filename.
There doesn’t seem to be a way to pick those files up in the “For Each Item in a Collection Execute Actions” action. I chose “The files in directory” (browsed to ~/Desktop), then added the “Move or Rename a File.”
How to pull in those files with the text and a wildcard?
I’ve looked at something similar in other questions - but I can’t seem to find the exact actions.
You're very close. The only step you're missing to select just the files you want is an If Then Else action to ensure that the only files acted on are those that meet the criteria you specify:
Just make sure to change the destination folder to where you want the screenshots moved and this should get you started. Feel free to post again if anything is unclear or you have any other questions.
Which ought to be faster for this task: a macro as illustrated here by @gglick, or calling an AppleScript to do it all ?
Sometimes I’m torn between whether to build a macro out of several different actions, or write an AppleScript and bung it in there instead. About half of my “macros” are just AppleScripts.
It’s easy to do this job with AppleScript and a whose-clause using System Events – IF you’re not dealing with more than a few hundred files.
It only takes 6 lines of code…
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/03/24 12:33
# dMod: 2018/03/24 12:39
# Appl: System Events
# Task: Move files whose name contains a string to a destination folder.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Move, @Files, @Whose, @Name, @Contains, @String, @Destination, @Folder
----------------------------------------------------------------
set sourceFolder to path to desktop folder
set destinationFolder to alias ((path to downloads folder as text) & "Test ⇢ Destination Folder:")
tell application "System Events"
set fileList to (files of sourceFolder whose name contains "screen shot")
move fileList to destinationFolder
end tell
----------------------------------------------------------------
Of course I’m not doing any error-checking here, as I would in a production script.
Now then – let’s get a bit more sophisticated and use a regular expression to find our files:
Hi. I am trying to achieve something similar, except that I want any files saved to my downloads folder that contain "HBD" to be moved to a specific directory. Here is what I have but the macro isn't triggering. It only works if I press the "Run button".
Hey there. Make sure the macro group is set to be active in the apps you want to use it in, and don't forget to actually assign it a trigger so you can run it outside the KM editor window
No problem. First, again, make sure the macro group is enabled and active where you want to use it (maybe it already is, but I can't tell that from your screenshot alone). Second, if you only want to add files that are newly added, you don't need a For Each action, just an If Then Else to check if the added file contains HBD in its file name or not: