I have an Applescript script which checks if my playlist has less than 25 songs in it shorter than 11 minutes and then moves some random files from another folder to my Temp folder to make up the number.

Is there any reason the "Finder" bit of the script is so slow (it takes nearly 15 seconds to execute)? Any code workaround I could use here?

--this adds some songs if the playlist has less than 25 songs in it shorter than 11 mins
tell application "iTunes"
    set thePlaylist to playlist "Temp on iPod"
    --counts tracks less than 11 mins long
    count ((tracks of thePlaylist) whose duration is less than 665)
    set currentCount1 to result
    if currentCount1 is less than 25 then
        tell application "Finder"
            set theDestination to folder "Macintosh HD:Temp to be Listened to:temp on iPod:"
            get every file of folder "Macintosh HD:Temp to be Listened to:Temp:Short Temp (Small Files, <20mb):" whose kind is "MP3 audio"
            --this only gets the top level files
            set theMusic to result
            set myList to {}
            set theReplaceNo to (25 - currentCount1)
            repeat theReplaceNo times
                set currentFile to some item of theMusic
                copy currentFile to the end of myList
            end repeat
            --reveal every item of myList
            reveal myList
            delay 1.5
            move myList to theDestination
        end tell
    end if
end tell

Can anyone help?


I tested your code on my OSX 10.9.5 and saw no issue. It took 2 seconds (delay included). So, for me, the code is correct.

What is your version of OSX ? (Maybe a bug ...)

You probably already know that but to investigate more on the part that slow the script down, you can use the following 2 statements :

-- Put this before the code you want to test :
set t to (time of (current date)) --Start timing operations

... your slow code here ...

-- Put this at the end of the code you want to test
set total to (time of (current date)) - t --End timing

Sorry, I can't help more.

You must log in to answer this question.

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