views:

39

answers:

2

I am trying to write an iTunes script that takes the selected tracks, moves the files to a different folder on my hard drive, and then update their location in iTunes.

The overall flow will be something like this:

  1. Get selection
  2. Determine path to selection
  3. Move items to destination
  4. Update referenced path in iTunes

I used the suggestion from this question to get the path of a selection in iTunes, and I will be able to figure out how to move the files to where I want them, however, now I want to tell iTunes that the file path is actually some place else.

Anybody know how to go about this?

A: 

The basic idea is to set the location property of each file track item to its new file path. For example:

tell application "iTunes"
    tell its first browser window
        set currentTrack to first item of (get its selection)
        set location of currentTrack to POSIX file "/Users/nad/Music/movedfile.m4a"
    end tell
end tell
Ned Deily
+1  A: 

I figured it out. I had a different error that was making me think this is harder then it is. Here's how I got it to work:

  tell application "iTunes"
     set s to selection
        repeat with c in s
           if video kind of c is TV show then
              set location of c to <destination directory>
              <code to move file>
           end if
  end tell
segfault
I wouldn't do it like this. "Selection" is a list of items. There could be many items in the list if you have more than one song selected in iTunes. You need to target the first item in the list like this: set location of (item 1 of (get selection)) to <PATH>
regulus6633
yeah, good point. I updated my answer
segfault