Connection of network disks by reading data from a txt file

Hi all,
please help, I’m going crazy.
I assembled this script (assembled because I’m not a real programmer) to connect network disks by reading the necessary data from a text file. The structure is rough and not optimized (for now are not able to do better) and certainly can be improved.

The script works properly until I try to connect the disks: the value read from the variable aDisk is wrong (should contain “Archive” and instead is read only one letter at a time, ie “A”, then “r”, then "c ", etc.) and can not understand why. I checked all the variables and all the calls but I can not find the solution.
Thanks in advance for any help.

Example of the txt file :

Alessio user userAlessio
Alessio psw pswAlessio
Alessio pathafp afp://serverafp/
Alessio pathsmb smb://serversmb/
Alessio volafp Archive
Alessio volafp Software
Alessio volsmb Data
Alessio volsmb Backup
Tom usr usertom
Tom psw pswtom
Tom pathafp afp://serverafp/
Tom pathsmb smb://serversmb/
Tom volafp Archive
Tom volsmb Data
Jenny usr userjenny
Jenny psw pswjenny
Jenny pathafp afp://serverafp/
Jenny volafp Photos
Jenny volafp Videos

The script :


-- path to txt file
set theFile to ((path to desktop as text) & "test.txt")
set theData to paragraphs of (read file theFile)

-- I get the user name as the value to make search
set searchName to (do shell script "echo $USER")
if searchName is "" then
	display dialog "User "& searchUser & " not recognized. " buttons {"OK"} default button 1
end if
set resultList to {}

-- the search begins and the found values are stored into a variable
set searchNameLength to (length of searchName) + 2
repeat with aParagraph in theData
	if aParagraph starts with searchName then
		set end of resultList to text searchNameLength thru -1 of aParagraph
	end if
end repeat

-- search for user ID
set searchUserId to "user"
if searchUserId is "" then return
set userId to {}
set searchUserIdLength to (length of searchUserId) + 2
repeat with aParagraph in resultList
	if aParagraph starts with searchUserId then
		set end of userId to text searchUserIdLength thru -1 of aParagraph
	end if
end repeat

-- search for user password
set searchUserPsw to "psw"
if searchUserPsw is "" then return
set userPsw to {}
set searchUserPswLength to (length of searchUserPsw) + 2
repeat with aParagraph in resultList
	if aParagraph starts with searchUserPsw then
		set end of userPsw to text searchUserPswLength thru -1 of aParagraph
	end if
end repeat

-- server(s) AFP --
-- search for AFP path(s)
set searchPathAfp to "pathafp"
if searchPathAfp is "" then return
set pathafp to {}
set searchPathAfpLength to (length of searchPathAfp) + 2
repeat with aParagraph in resultList
	if aParagraph starts with searchPathAfp then
		set end of pathafp to text searchPathAfpLength thru -1 of aParagraph
	end if
end repeat

-- search for AFP volume(s)
set searchVolAfp to "volafp"
if searchVolAfp is "" then return
set volafp to {}
set searchVolAfpLength to (length of searchVolAfp) + 2
repeat with aParagraph in resultList
	if aParagraph starts with searchVolAfp then
		set end of volafp to text searchVolAfpLength thru -1 of aParagraph
	end if
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set resultVolAfp to volafp as text
set text item delimiters to TID

-- server(s) SMB --
-- search for SMB path(s)
set searchPathSmb to "pathsmb"
if searchPathSmb is "" then return
set pathSmb to {}
set searchPathSmbLength to (length of searchPathSmb) + 2
repeat with aParagraph in resultList
	if aParagraph starts with searchPathSmb then
		set end of pathSmb to text searchPathSmbLength thru -1 of aParagraph
	end if
end repeat

-- search for SMB volume(s)
set searchVolSmb to "volsmb"
if searchVolSmb is "" then return
set volSmb to {}
set searchVolSmbLength to (length of searchVolSmb) + 2
repeat with aParagraph in resultList
	if aParagraph starts with searchVolSmb then
		set end of volSmb to text searchVolSmbLength thru -1 of aParagraph
	end if
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set resultVolSmb to volSmb as text
set text item delimiters to TID

-- I get the list of mounted volume(s)
set mountedDisks to paragraphs of (do shell script "/bin/ls /Volumes")
set notMountable to {}

-- I try to mount AFP volume(s) if not yet mounted
repeat with aDisk in resultVolAfp
	display dialog aDisk buttons {"Cancel", "OK"} default button 1
	display dialog resultVolAfp buttons {"Cancel", "OK"} default button 1
	if aDisk is not in mountedDisks then
		try
			mount volume pathafp & aDisk
		on error
			set end of notMountable to text of pathafp & aDisk
		end try
	end if
end repeat

-- I try to mount SMB volume(s) if not yet mounted
repeat with aDisk in resultVolSmb
	if aDisk is not in mountedDisks then
		try
			mount volume pathSmb & aDisk as user name userId with password userPsw
		on error
			set end of notMountable to text of pathSmb & aDisk
		end try
	end if
end repeat

-- In case of not available volume(s) I receive a warning
if notMountable is "" then
	display dialog "All network drives are available." buttons {"OK"} default button 1
else
	set {TID, text item delimiters} to {text item delimiters, return}
	set resultMount to notMountable as text
	set text item delimiters to TID
	display dialog resultMount buttons {"OK"} default button 1
	--display dialog "These disks appear not available : " & return & resultMount buttons {"OK"} default button 1
end if

Yesterday my first suggestion was right, because you need an AppleScript list, not text lines separated by newline characters.
The error occurs because resultVolAfp is a string and

repeat with aDisk in resultVolAfp

means

repeat with aCharacter in every character of resultVolAfp

so just cut all occurrences of


set {TID, text item delimiters} to {text item delimiters, return}
set resultVolAfp to volafp as text
set text item delimiters to TID

and adjust the variable names

Hi Stefan,
yes your first suggestion was right, but my inexperience prevailed :rolleyes:.
I made ‹‹the changes you have indicated and now it works like a charm.
Thanks once again for your help !!!

EDIT

Sorry if I deleted the script, but I realized that it was full of errors (mine) and did not work properly.
If and when I can fix it, I will share willingly.