AppleScript: Get list of 15 most recent files in directory I need to build a string containing the filenames of the 15 most recent files (by modification date) within a directory. Delimited only by a space:

file1.jpg file2.jpg file3.jpg

I'm using ImageMagick via command line. Here is what I currently have, but get an error number -1728:

tell application "Finder"
    set imageItems to every file of folder wallpaperPath
    set imageItems to the reverse of (sort imageItems by modification date)
    set concatFiles to ""
    repeat with n from 1 to 15
        set imageItem to item n of imageItems
        set imageName to the file name of imageItem
        set concatFiles to concatFiles &amp; " " &amp; imageName
    end repeat
end tell
do shell script "cd " &amp; wallpaperPath &amp; "; montage " &amp; concatFiles &amp; " -tile 3x5 -geometry 500x500+1+1 ~/Desktop/final.jpg"
Change the line,

    set imageName to the file name of imageItem


to 

    set imageName to the name of imageItem


and it should work.

EDIT:

Couldn't help but notice that you are not quoting your file names. If any of them contain spaces, then you will have problems. Best to also change

    set concatFiles to concatFiles &amp; " " &amp;  imageName


to

    set concatFiles to concatFiles &amp; " " &amp; quoted form of imageName