Software Update iTunes Track Location

I would like to change the file system path for tracks on itunes programmatically so that I can apply string conversion to some places on the tracks (which are now stored in different places on the file system).

I tried using AppleScript to update the location property of the corresponding tracks, but I get an end-of-file error when calling "set mytrack location to ..."

I saw various other hacks on the Internet that include exporting the entire db track, changing it to XML, and then re-importing it - but this seems to lose too much metadata (such as playlists).

+3
source share
3 answers

. , . , ( AppleScript, Script Editor/& # xfeff; AppleScript Editor).

file track , location alias. , , , , , .

, choose file ( alias):

set m to path to music folder
tell application "iTunes"
    set trk to first item of selection
    set l to location of trk
    if class of l is alias then
        set m to l
    end if
    set {d, a, n} to {database ID, artist, name} of trk
    choose file with prompt "Choose the file to use for " & d & ": " & a & "β€”" & n default location m
    set location of trk to result
end tell

choose file - , , - .

AppleScript , : POSIX HFS. POSIX ( ). HFS ( ), .

POSIX, str, AppleScript alias, :

POSIX file str as alias

HFS, str, AppleScript alias, :

alias str

:

tell application "iTunes"
    set trk to first item of selection
    set l to location of trk
    set newPath to my computeNewPath(POSIX path of l)
    set location of trk to POSIX file newPath as alias
end tell

to computeNewPath(pp)
    -- presumably something interesting happens here
    return pp
end computeNewPath
+3

( "" iTunes) , iTunes (iTunes Library.itl):

  • (, mv ~/MyMusic /Volumes/Huge/)
  • ,
    (ln -s /Volumes/Huge/MyMusic ~/MyMusic)
  • iTunes ( )
  • , .
  • AppleScript:

    -- Mark missing tracks (and update database with real path of existing
    -- tracks) in iTunes
    -- Instructions:
    -- * symlink new file location to old location (old location points to
    --   new location, file exists)
    -- * select tracks to scan/update
    -- * run the script
    -- * missing tracks are marked with (!) and all other track paths have
    --   been updated to the real path (symlinks eliminated) in iTunes
    tell application "iTunes"
        set fx to fixed indexing
        set fixed indexing to true
        set Sel to the selection
    
        repeat with i from 1 to number of items in Sel
            set trk to item i of Sel
            set loc to (get location of trk as text)
        end repeat
    
        set fixed indexing to fx
    end tell
    
  • , . , " " , .

, iTunes (!) . , , , script. : Get Info .

iTunes 11.0.5

+2

millerdev, MacOS Catalina Music. $ HOME/Library/Music/Scripts .

tell application "Music"
  set fx to fixed indexing
  set fixed indexing to true
  set Sel to the selection

  repeat with i from 1 to number of items in Sel
    set trk to item i of Sel
    set l to location of trk
    set location of trk to l
  end repeat

  set fixed indexing to fx
end tell
0

Source: https://habr.com/ru/post/1744696/


All Articles