property tag_prefix : "<"
property tag_suffix : ">"
using terms from application "Quicksilver"
on process text txt
set txt_items to my itemize(txt, " ")
set tags to my wrap(txt_items)
tell application "iTunes"
set t to current track
set g to t's grouping
if g ≠ "" then
set tags to my compare(g, tags)
set g to g & " "
end if
set t's grouping to g & my itemize(tags, "")
end tell
end process text
end using terms from
to itemize(var, delim)
set delims_old to AppleScript's text item delimiters
set AppleScript's text item delimiters to delim
if var's class = list then
set txt to var as text
else
set txt to var's text items
end if
set AppleScript's text item delimiters to delims_old
return txt
end itemize
to compare(tags_old, tags_new)
set tags to {}
repeat with i in tags_new
if offset of i in tags_old = 0 then
set end of tags to i
end if
end repeat
return tags
end compare
to wrap(array)
set output to {}
repeat with i in array
set end of output to (tag_prefix & i & tag_suffix) as string
end repeat
return output
end wrap