3

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
  • Are .wad files single files and not bundles or folders? Have you tried examining the result of every file of folder … whose name extension is … to ensure it matches something? – Graham Miln Jun 10 '14 at 13:55
  • The .wad files are single files, yes. They're Wii Homebrew software files. I get correct results for any file type other than .wad files. I've tested this script with .jpg files, .epub files, .zip files and .7z files and they all work fine. The script even detects .wad files that have had the extension changed to .jpg, for example. – RhysMorgan Jun 10 '14 at 14:03
  • Fun, I associate them with the game Doom. Have you tried display dialog with the found file list, rather than moving? Does the list contain any matches? – Graham Miln Jun 10 '14 at 14:05
  • I added display dialog list (every file of folder (choose folder) whose name extension is filetype) before the move (every file of folder (choose folder) whose name extension is filetype) to folder newfolder and commented out the move line. AppleScript the gave the result "error "Finder got an error: Can’t make list {} into type string." number -1700 from list {} to string". Is the code for listing the folder contents incorrect? – RhysMorgan Jun 10 '14 at 14:26
1

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.

  • That actually moved the .wad files! Despite the file extension definitely being .wad, it seems file extension wasn't detecting wads. I've rewritten that line of code with your suggestion, adding in the variable, and it seems to work! Thank you very much! – RhysMorgan Jun 10 '14 at 14:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .