add files to iTunes playlist with folder action

Discussion in 'Mac Programming' started by aendaman, Sep 28, 2008.

  1. macrumors member


    May 28, 2008

    i try to write an apple script to use as folder action which, when copying files to that folder will adds them to a specific itunes playlist and set them bookmarkable.

    so far i put this together from snippets i found:

    property DELAY_TIME_SECONDS : 5 -- How long to wait between checking file size.

    on adding folder items to my_folder after receiving the_files

    repeat with i from 1 to number of items in the_files
    set oldSize to 0
    set newSize to -1
    -- When newSize equals oldSize, it means the copy is complete because the size hasn't changed.
    repeat while newSize is not equal to oldSize
    -- Get the file size.
    set oldSize to size of (info for i)
    -- Sample the size again after delay for comparison.
    set newSize to size of (info for i)
    end repeat

    tell application "iTunes"
    set this_file to (item i of the_files)
    add this_file to playlist "test"
    set bookmarkable of this_file to true

    end try
    end tell
    end repeat
    end adding folder items to

    i compiled and saved it in ~/Library/Scripts/Folder Action Scripts then added it to the folder as folder action but when i drop a file into the folder, nothing happens in iTunes.

    any help appreciated
  2. macrumors 68040


    Dec 2, 2003

Share This Page