Hi all,
I’ve hit a brick wall trying to formulate a script (that’s part of a Keyboard Maestro macro) that hunts for a variable within a bunch of filenames in a specific folder, then moves those files into another folder that also uses the variable.
My KM macro asks the user to type a name, e.g. Prison Services London
It turns that into a variable called “theSet”
It uses this variable to generate a parent folder “Prison Services London_Logo set” and various sub-folders.
For example,
Client > Artwork > SEND TO CLIENT > Prison Services London_Logo set
Black
CMYK
RGB
White…
The files themselves reside in the Export folder
For example,
Client > Artwork > Export
Prison Services London_black_CMYK.jpg
Prison Services London_black_CMYK.eps
Prison Services London_black_CMYK.png
Prison Services Oxford_black_CMYK.jpg
Prison Services Oxford_black_CMYK.eps
Prison Services Oxford_black_CMYK.png
The problem I have is trying to get an AppleScript to use the theSet variable in file paths and folder names. It fails with various errors.
The applescript takes the variable theSet and uses it to find only files with that wording, e.g. Prison Services London, that has black_CMYK also in the filename, and doesn’t end in ai (as in .ai).
It moves those found files into the relevant folder, which again is based on theSet variable.
Here’s the script
tell application "Keyboard Maestro Engine"
set theSet to getvariable "theSet"
end tell
set Dst_Folder to (POSIX file "/Users/myusername/Dropbox/Client/Artwork/SEND TO CLIENT/")
set Src_Folder to (POSIX file "/Users/myusername/Dropbox/Client/Artwork/Export")
set Dst_blackCMYK to (POSIX file Dst_Folder & theSet & "/Black/CMYK")
tell application "Finder" to move ((every file in the folder Src_Folder whose ¬
name contains theSet and ¬
name contains "black_CMYK" and ¬
name does not end with "ai") as alias list) to Dst_blackCMYK
myusername is just for privacy for this post.
I almost forgot to say that of course I’m running this from Keyboard Maestro but have also tried straight from Script Editor, having changed the second line.
set theSet to “Prison Services London”
I’m banging my head against a wall with this one. Can anyone please guide me? Many thanks.
AppleScript: 2.8
Browser: Safari 605.1.15
Operating System: macOS 12