Doing a similar job with plain vanilla AppleScript and string-matching instead of using a regular expression is quite easy.
As you can see I’m moving the Files found with this script to a different destination.
----------------------------------------------------------------
# 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
----------------------------------------------------------------
Deleting items older than a given number of days in a given directory.
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/03/24 13:00
# dMod: 2018/03/24 13:06
# Appl: Finder, System Events
# Task: Trash items from a directory that are older than a given number of days.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @System_Events, @Trash, @Delete, @Items, @Directory, @Older, @Days
----------------------------------------------------------------
set sourceFolder to alias ((path to home folder as text) & "test_directory:Test_Delete_by_Time:")
set obsoleteDate to (current date)
set time of obsoleteDate to 0 --> changing the time to Midnight
set obsoleteDate to obsoleteDate - (31 * days)
tell application "System Events"
set itemList to items of sourceFolder whose creation date is less than obsoleteDate
repeat with i in itemList
set contents of i to (path of i) as alias
end repeat
end tell
tell application "Finder" to delete itemList
----------------------------------------------------------------
NOTE – The path to the source directory is an alias – NOT a POSIX Path.
I have a question (I'm not well versed with applescript to say the least).
What do you mean by " NOTE – The path to the source directory is an alias – NOT a POSIX Path." and the first line of your script:
set sourceFolder to alias ((path to home folder as text) & "test_directory:Test_Delete_by_Time:")
Let's say my folder has a path of "/Users/benmac16/Dropbox/300-APP-SYNC/SSH-Config-Backup" (I guess that's what is called a POSIX path, whereas I've always named that a simple "path").
How do I "convert" that path to use your script ? Or how do I modify your script to work with classic POSIX path ? (if that's even possible)
Is it just using this as first line ?
set sourceFolder to "/Users/benmac16/Dropbox/300-APP-SYNC/SSH-Config-Backup"
I don't understand what the "alias ((path to home folder as text) & "test_directory:Test_Delete_by_Time:")" means in your script and since it's a delete stuff script, I'd rather ask before whipping my hard drive's content