How to get and set metadata of a m4a file? I am trying to automate some changes in m4a metadata and would prefer doing it through AppleScript other than popular solutions like mutagen.

How can I address m4a files metadata? I need not only setting metadata to specific values, I need to read these values first.

Basically what I need to do is, set TRACK_NAME to ARTIST + " - " + TRACK_NAME, and then TRACK_NAME to ALBUM_ARTIST. This is required for my media player to not spread compliations all over the library. It doesn't know any better, unfortunately.
Here is a quick something to get you started. If you also want the filename changed too, then it is easy to add in the copy section...

set dpath to "/some/path/some/where/"
set qdpath to quoted form of dpath

# Choices of apps to use depending what files you have
# mp3
set tapp3 to "/usr/local/bin/id3v2 -t "
# m4a
set tapp4 to "/usr/local/bin/mp4tags -s "

tell application "iTunes"
    set iSel to selection

    repeat with trk in iSel
        set aloc to location of trk
        set loc to quoted form of (POSIX path of aloc)
        set tname to name of trk
        set tartist to artist of trk
        tell application "Finder"
            set fname to name of file (aloc as alias)
            set fext to name extension of file (aloc as alias)
        end tell


        # Copy
        try
            do shell script "cp " &amp; loc &amp; " " &amp; qdpath
        on error eStr
            display dialog eStr
            return
        end try


        # New path
        set qnewfile to quoted form of (dpath &amp; fname)


        # Choose right tool...
        if fext is "mp3" then
            set tapp to tapp3
        else if fext is "m4a" then
            set tapp to tapp4
        else
            display dialog "Unknown file type. Don't know what to use..."
            return
        end if


        # Tag 
        try
            do shell script tapp &amp; "'" &amp; tartist &amp; " - " &amp; tname &amp; "' " &amp; qnewfile
        on error eStr
            display dialog eStr
            return
        end try
    end repeat
end tell


Since you don't like using command line tools and Applescript doesn't have built in support for audio tags, you are left with iTunes. So here is a version of the above with just using iTunes,

set dpath to "/some/path/"
set qdpath to quoted form of dpath
set listname to "MyList"
set adpath to (POSIX file dpath as alias)

# Copy selected itunes files
tell application "iTunes"
    set iSel to selection

    repeat with trk in iSel
        set tloc to location of trk
        set atloc to quoted form of (POSIX path of tloc)
        set tname to name of trk
        set tartist to artist of trk

        tell application "Finder"
            set fname to name of file (tloc as alias)
            set fext to name extension of file (tloc as alias)

            try
                duplicate file tloc to folder adpath with replacing
            on error eStr
                display dialog "Copy failed for track: " &amp; tname &amp; return &amp; return &amp; eStr
                return
            end try
        end tell
    end repeat
end tell


# Get audio files in selected folder 
#   -- alas no recursive search results without a lot more code... :(
set afiles to {}
tell application "Finder"
    repeat with ext in {".mp3", ".m4a"}
        set l to (every file in adpath whose name contains ext)
        repeat with f in l
            set end of afiles to (f as text)
        end repeat
    end repeat
end tell


# Add to iTunes and change Tags...
#
tell application "iTunes"
    if not (user playlist listname exists) then
        make new user playlist with properties {name:listname}
    end if

    set view of window 1 to playlist listname

    # Add and change tracks' names
    repeat with afile in afiles
        try
            set tid to (add afile to playlist listname)
        end try

        set tname to name of tid
        set aname to artist of tid

        set name of tid to ((aname &amp; " - " &amp; tname) as text)
    end repeat

    # Clean up now?
    set r to display dialog "Done. " &amp; return &amp; return &amp; ¬
        "Remove tracks and list now?" as text buttons {"No", "Yes"} with icon note

    if button returned of r is not "Yes" then
        return
    end if


    # Remove playlist tracks from library; will remove from playlist(s) too
    #   -- WARNING: If track added multiple times all entries will be removed!! 
    repeat with t in (every track in playlist listname)
        try
            set pid to persistent ID of t

            # Thanks Doug Adams, it was driving me nuts....
            delete (some file track of library playlist 1 whose persistent ID is pid)
        end try
        delay 1
    end repeat

    delay 30

    # Remove all tracks from playlist v2
    try
        # Fast mass deletion - Thx to http://apple.stackexchange.com/a/56463
        # but only removes from playlist.. they remain in the library!
        #delete tracks of playlist listname
    end try

    try
        delete playlist listname
    end try
end tell