0

I have a script that add or update files in a folder. What I want to do is for an applescript to add these files to iTunes. But I can't seem to loop through the directory.

tell application "iTunes"
  if playlist myPlaylist exists then delete playlist myPlaylist
  set newPlaylist to (make new user playlist with properties {name:myPlaylist})

  repeat with theFile in myPath as list
    add theFile to playlist myPlaylist
  end repeat
end tell

For every repeat, the value of theFile is the individual character of myPath, not the actual file in myPath. theFile will be M, a, c, i, n, ... instead of file1.mov, file2.mov, ...

Thank you.

1
  • How are you getting myPath? Commented Jan 3, 2013 at 1:11

1 Answer 1

1

If myPath is a string, as list converts it to an array of characters.

You can tell Finder to get a list of aliases:

tell application "Finder"
    set l to items of (POSIX file "/Users/username/Music/folder" as alias) as alias list
end tell
tell application "iTunes"
    if playlist "test" exists then
        delete tracks of playlist "test"
    else
        set p to make new user playlist with properties {name:"test"}
    end if
    add l to p
end tell

This would add the selected files to the currently shown playlist:

tell application "Finder"
    set l to selection as alias list
end tell
tell application "iTunes"
    add l to view of browser window 1
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.