How can I get my AppleScript code to move files?
Having used Automator to organise files by file extension successfully before, I decided to create an AppleScript application that will save me having to change parameters manually, as Automator doesn't allow me to set a variable for the "Filter Finder Items" action.
However, for some reason or another, my AppleScript code decides not to actually move .wad files. I've tested it with .jpg files and it works perfectly. I've tested it with .epub files, same thing. But it doesn't seem to be able to detect .wad files.
Below is my code. It creates the folder in the correct location with the name I put in the first dialog box, but it doesn't move .wad files into the new location. I end up just creating a blank folder. The Result AppleScript gives me when the script terminates is {}
display dialog "Set folder name" default answer ""
set foldername to (text returned of result)
display dialog "Set file type" default answer ""
set filetype to (text returned of result)
set newfolder to ((path to downloads folder as text) & foldername as text)
tell application "Finder"
if not (exists folder ((path to downloads folder as text) & foldername as text)) then
make new folder at (path to downloads folder) with properties {name:foldername}
end if
move (every file of folder (choose folder) whose name extension is filetype) to folder newfolder
end tell
It appears the following line is returning an empty list:
every file of folder (choose folder) whose name extension is filetype
As an experiment, try a different suffix matching approach:
every file of folder (choose folder) whose name ends with ".wad"
In the Finder, make sure the .wad
files are in fact showing their complete name. Do this with Get Info on one wad
file in the Finder. It is unlikely but possible that the true file suffix is being hidden and thus not being matched.