text items of filename
returned. To get an element of this list, you just need to specify the number of the desired element (numbering from one)text item 5 of filename
. It is not clear why the developers of AppleScript did not go further and did not replace, say, the numbers with the corresponding verbal notation.tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...
set sel to a reference to selection
repeat with aTrack in sel
set filename to location of aTrack as text
set AppleScript's text item delimiters to ":"
set artst to text item 5 of filename as text
set albm to text item 6 of filename as text
set title to text item 7 of filename as text
set AppleScript's text item delimiters to ""
-- work on album and year
set dashIdx to offset of "-" in albm
set yr to items 1 thru (dashIdx - 1) of albm as text
set albm to items (dashIdx + 1) thru -1 of albm as text
-- work on title
set dashIdx to offset of "-" in title
set trackNo to items 1 thru (dashIdx - 1) of title as text
set title to items (dashIdx + 1) thru -4 of title as text
set year of aTrack to (yr as integer)
set artist of aTrack to artst
set name of aTrack to title
set track number of aTrack to (trackNo as integer)
set album of aTrack to albm
end repeat
end if
end tell
* This source code was highlighted with Source Code Highlighter .
tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...
set sel to a reference to selection
repeat with aTrack in sel
set filename to location of aTrack as text
set AppleScript's text item delimiters to ":"
set artst to text item 5 of filename as text
set albm to text item 6 of filename as text
set title to text item 7 of filename as text
set AppleScript's text item delimiters to ""
-- work on album and year
set dashIdx to offset of "-" in albm
set yr to items 1 thru (dashIdx - 1) of albm as text
set albm to items (dashIdx + 1) thru -1 of albm as text
-- work on title
set dashIdx to offset of "-" in title
set trackNo to items 1 thru (dashIdx - 1) of title as text
set title to items (dashIdx + 1) thru -4 of title as text
set year of aTrack to (yr as integer)
set artist of aTrack to artst
set name of aTrack to title
set track number of aTrack to (trackNo as integer)
set album of aTrack to albm
end repeat
end if
end tell
* This source code was highlighted with Source Code Highlighter .
tell application "iTunes"
if selection is not {} then -- there ARE tracks selected...
set sel to a reference to selection
repeat with aTrack in sel
set filename to location of aTrack as text
set AppleScript's text item delimiters to ":"
set artst to text item 5 of filename as text
set albm to text item 6 of filename as text
set title to text item 7 of filename as text
set AppleScript's text item delimiters to ""
-- work on album and year
set dashIdx to offset of "-" in albm
set yr to items 1 thru (dashIdx - 1) of albm as text
set albm to items (dashIdx + 1) thru -1 of albm as text
-- work on title
set dashIdx to offset of "-" in title
set trackNo to items 1 thru (dashIdx - 1) of title as text
set title to items (dashIdx + 1) thru -4 of title as text
set year of aTrack to (yr as integer)
set artist of aTrack to artst
set name of aTrack to title
set track number of aTrack to (trackNo as integer)
set album of aTrack to albm
end repeat
end if
end tell
* This source code was highlighted with Source Code Highlighter .
~/Library/iTunes/Scripts
and it will be available under the name under which you saved it in the iTunes menuSource: https://habr.com/ru/post/63506/
All Articles