iView Media Pro Script Error-Can't make item into type string

Hello all,

I’m using a supplied AppleScript to import the entries from a tab delimited text file into a iView Media Pro database. It works some of the time, but I eventualy get the error below. I’ve included the script & a chunk of the tab delimited text file. If any of you have a chance, I was wondering if you could check this out to see if you can spot the problem. Any help would be greatly appreciated. Thanks.

“Can’t make item 18 of {"RMCD 2019-34.aiff", "RMCD 2019-34.aiff", "RMCD 2019", "34", "34", ".aiff", "Rouge", "Crab Shack - 30 Sec Vers.", "Mid", "0.3", "Small Group", "\"Darby, Alan\"", "Cheerful", "\"Exuberant, Rhythmic, Exciting\"", "Flute", "\"Action,Featured Instruments,Leisure,Sport\"", "SLOW BURN"} into type string.”

Here is the script:

– 2005-07-09
property iViewLib : alias ((path to application support from user domain as string) ¬
& “iView:Plug-ins:Common:iView-Lib.scpt”)
global Lang, FieldToGet, textFile
– property CustomFields : {“CD_NO”, “Track_No”, “Publisher”, “Track_Title”, “Tempo”, “Instrumentation”, “Composer”, “Moods”, “Description”, “Featured_Inst”, “Category”, “CD_TITLE”, “CD_Descr”}

tell (load script iViewLib)
set Lang to User_Language()
– if my AboutScript() is “” then return
if GetCatalog(0) = {} then return
end tell

set NbLines to ReadFile()
if NbLines < 2 then return

set FieldToGet to IdentFields(item 1 of textFile)
if FieldToGet = “” then return

set Total to 0
tell window 1 of application “iView MediaPro”
repeat with CurLine from 2 to NbLines
set TextLine to item CurLine of textFile as string
if TextLine ≠“” then
set AppleScript’s text item delimiters to tab
set TextLine to text items of TextLine
set AppleScript’s text item delimiters to “”
if (count of TextLine) > 1 then
set Total to Total + 1
set FileName to first item of TextLine
set Selitems to (media items whose name is FileName)
repeat with F from 1 to count of FieldToGet
set FieldTo to item F of FieldToGet as string
set NewText to item (F + 1) of TextLine as string
if NewText starts with quote then set NewText to text 2 thru -2 of NewText

				if exists custom field FieldTo then
					repeat with MediaFile in Selitems
						select MediaFile
						set custom field FieldTo of MediaFile to NewText
					end repeat
				end if
			end repeat
			
		end if
	end if
end repeat

end tell
beep
display dialog item Lang of {"Number of processed files: ", "Nombre de fichiers traités : "} & Total buttons ¬
“OK” default button 1 with icon note giving up after 5
return


on IdentFields(LabFields) – Custom Fields
set AppleScript’s text item delimiters to tab
set CustomFields to items 2 thru -1 of text items of LabFields
set AppleScript’s text item delimiters to “”
return CustomFields
end IdentFields

on ReadFile()
beep
set sourceFile to choose file with prompt item Lang of {“Choose a “TEXT” file:”, “Choisir un fichier “TEXTE” :”}
if sourceFile = “” then return
tell application “Finder” to set textFile to read file (sourceFile as string)
set textFile to paragraphs of textFile
return count of textFile
end ReadFile


on AboutScript()
beep
set lib to item Lang of {¬
“Assign by name the annotation fields taken in text file.”, ¬
“Affecte par nom de fichier les champs annotations IPTC d’un fichier texte en tableau.”}
set btn to item Lang of {{“Note.”, “Cancel”, “OK”}, {“Note.”, “Annuler”, “OK”}}
display dialog lib buttons btn default button 3 with icon note
set theAnswer to the button returned of the result
if theAnswer is not item 1 of btn then return theAnswer
set lib to item Lang of {¬
“¢ Empty line preserve existing annotation.” & return & ¬
“¢ ˜-’ delete existing annotation.” & return & ¬
“¢ For fields “Keywords, Categories, People” the séparator is ˜,’ (comma).” & return & ¬
“¢ ˜¬’ (option-L) make a line feed in Caption field.”, ¬
“¢ Une valeur vide préserve l’annotation existante.” & return & ¬
“¢ ˜-’ efface l’annotation existante.” & return & ¬
“¢ Pour les champs : “Mots-Clés, Catégories, Personnes” le séparateur est ˜,’ (virgule).” & return & ¬
“¢ ˜¬’ (option-L) crée un saut de ligne dans les Légendes.”}
display dialog lib with icon note
return the button returned of the result
end AboutScript

Here is the part of the tab delimited text file that it hangs on:

RMCD 2019-33.aiff RMCD 2019-33.aiff
RMCD 2019 33 33 .aiff Rouge Slow Burn - 30 Sec Vers. Mid 0.3 Small Group
“Darby, Alan” Friendly “Pushy, Percussive, Cheerful” “Holidays
(Vacations),Jingles,Leisure,Sport” SLOW BURN
RMCD 2019-34.aiff RMCD
2019-34.aiff RMCD 2019 34 34 .aiff Rouge Crab Shack - 30 Sec Vers. Mid 0.3 Small
Group “Darby, Alan” Cheerful “Exuberant, Rhythmic, Exciting” Flute
“Action,Featured Instruments,Leisure,Sport” SLOW BURN
RMCD 2020-01.aiff
RMCD 2020-01.aiff RMCD 2020 1 1 .aiff Rouge The Leaders Up 2.08 Electronic
“Hawkins, Mark” Cheerful “Exuberant, Rhythmic, Exciting” Flute
“Action,Featured Instruments,Jingles,Leisure,Sport” MOMENTUM
RMCD 2020-02.aiff
RMCD 2020-02.aiff RMCD 2020 2 2 .aiff Rouge The Leaders - Underscore Up
2.07 Electronic “Hawkins, Mark” Cheerful “Exuberant, Rhythmic,
Exciting” Flute “Action,Featured Instruments,Jingles,Leisure,Sport”
MOMENTUM

I’d guess that some of the text in your data file is being confused with the comma quote delimitters. I don’t know where your text file is coming from, but I think the answer lies in there, not the import script. Only the text that contains commas is getting wrapped in quotes. You could use something like Word or TextWrangler to delete the quotes, and then try the import again. If that doesn’t work, replace all the commas with dashes and try again.