Moving files from a text file list

Okay, so I have a script that takes a bunch of random Finder Alias and makes them into a text document named: AliasList.txt

Now I want to use that information to move the list of files to a new location. But I am having a problem it sees the list of files as one name instead of individual names. Is there a way to fix this?

This is the code I am working with


set AliasNameTXT to do shell script "cat ~/Documents/Get_Alias.app/Contents/Resources/CACHE/AliasList.txt"
set sel to selection as text

tell application "Finder"
	set aliasReal to ((path to documents folder) & "Get_Alias.app:Contents:Resources:CACHE:" & AliasNameTXT) as string
	
	duplicate aliasReal to sel with replacing
	
	
end tell

I found out how to break up the names with the paragraphs delimiter.

Set AliasNameTXT to do shell script "cat ~/Documents/Get_Alias.app/Contents/Resources/CACHE/AliasList.txt"
set AliasParagraphs to paragraphs of AliasNameTXT

But not sure how to get this to work with the rest of my script

You may try :

set p2d to path to desktop as text

set destFolder to p2d & "dest Æ’:"
set quotedPosixDest to quoted form of POSIX path of destFolder

set destFolder2 to p2d & "dest2 Æ’:"
set quotedPosixDest2 to quoted form of POSIX path of destFolder2

set AliasNameTXT to do shell script "cat ~/Documents/Get_Alias.app/Contents/Resources/CACHE/AliasList.txt"
set AliasParagraphs to paragraphs of AliasNameTXT

set srcQpath to {}
repeat with anItem in AliasParagraphs
	set end of srcQpath to quoted form of POSIX path of anItem
end repeat
set srcQpaths to my recolle(srcQpath, " ")

# To copy the files from the source to the destination
do shell script "cp -a " & srcQpaths & " " & quotedPosixDest

# To move the files from source to destination
do shell script "mv " & srcQpaths & " " & quotedPosixDest2

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to "" & l
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====

Yvan KOENIG (VALLAURIS, France) mardi 21 juillet 2015 10:47:55

Thank you thank you thank you. This is exactly what I needed. I was hoping you can explain what is going on in the script. I have made notes to the script letting you know what I already understand or think I understand. It would be very helpful in my learning if you could explain where I am lost or incorrect. Thanks

set p2d to path to desktop as text -- I know this is creating a path to the desktop

set destFolder to p2d & "dest Æ’:" -- I know this creates a folder on your desktop to MOVE the files to
set quotedPosixDest to quoted form of POSIX path of destFolder -- I know this is making the path friendly for shell script

set destFolder2 to p2d & "dest2 Æ’:" -- I know this creates a folder on your desktop to COPY the files
set quotedPosixDest2 to quoted form of POSIX path of destFolder2 -- I know this is making the path friendly for shell script

set AliasNameTXT to do shell script "cat ~/Documents/Get_Alias.app/Contents/Resources/CACHE/AliasList.txt" --I know this gets the list of alias names from my text file
set AliasParagraphs to paragraphs of AliasNameTXT -- I know this breaks up the names

set srcQpath to {} --  yeah not quite understanding this
repeat with anItem in AliasParagraphs -- I think this grabs the names from the  TXT list and makes them into an indivual item
	set end of srcQpath to quoted form of POSIX path of anItem -- I am assuming this is creating the front of the path and it adds to the end the the names from my txt list.
end repeat
set srcQpaths to my recolle(srcQpath, " ") --Not understanding this?

# To copy the files from the source to the destination 
do shell script "cp -a " & srcQpaths & " " & quotedPosixDest -- I know this is to copy the files

# To move the files from source to destination
do shell script "mv " & srcQpaths & " " & quotedPosixDest2 -- I know this is to move the files

#=====

on recolle(l, d) -- I have no idea what is happening here and below.
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to "" & l
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====
set p2d to path to desktop as text -- I know this is creating a path to the desktop

set destFolder to p2d & "dest Æ’:" -- I know this creates a folder on your desktop to MOVE the files to
set quotedPosixDest to quoted form of POSIX path of destFolder -- I know this is making the path friendly for shell script

set destFolder2 to p2d & "dest2 Æ’:" -- I know this creates a folder on your desktop to COPY the files
set quotedPosixDest2 to quoted form of POSIX path of destFolder2 -- I know this is making the path friendly for shell script

set AliasNameTXT to do shell script "cat ~/Documents/Get_Alias.app/Contents/Resources/CACHE/AliasList.txt" --I know this gets the list of alias names from my text file
set AliasParagraphs to paragraphs of AliasNameTXT -- I know this breaks up the names

set srcQpath to {} --  yeah not quite understanding this # it creates an empty list which will be completed soon.
repeat with anItem in AliasParagraphs -- I think this grabs the names from the  TXT list and makes them into an indivual item
	set end of srcQpath to quoted form of POSIX path of anItem -- I am assuming this is creating the front of the path and it adds to the end the the names from my txt list.
end repeat
# Here, we have a list named srcQpath containing several path to files
# We call the handler/subroutine named recolle which will assemble these paths using the space character as separator
# Read the AppleScript Language Guide for details.
set srcQpaths to my recolle(srcQpath, " ") --Not understanding this?


# To copy the files from the source to the destination 
do shell script "cp -a " & srcQpaths & " " & quotedPosixDest -- I know this is to copy the files

# To move the files from source to destination
do shell script "mv " & srcQpaths & " " & quotedPosixDest2 -- I know this is to move the files

#=====

on recolle(l, d) -- I have no idea what is happening here and below.
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to "" & l
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====

Detailed explanations are available in Apple’s AppleScript Language Guide.
I reproduce these explanations :

text item delimiters
AppleScript provides the text item delimiters property for use in processing text. This property consists of a list of strings used as delimiters by AppleScript when it coerces a list to text or gets text items from text strings. When getting text items of text, all of the strings are used as separators. When coercing a list to text, the first item is used as a separator.
Note: PriortoOSXSnowLeopardv10.6,AppleScriptonlyusedthefirstdelimiterinthelistwhen getting text items.
Because text item delimiters respect considering and ignoring attributes in AppleScript 2.0, delimiters are case-insensitive by default. Formerly, they were always case-sensitive. To enforce the previous behavior, add an explicit considering case statement.
You can get and set the current value of the text item delimiters property. Normally, AppleScript doesn’t use any delimiters. For example, if the text delimiters have not been explicitly changed, the statement
returns the following:
For printing or display purposes, it is usually preferable to set text item delimiters to something that’s easier to read. For example, the script
2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. 42
{“bread”, “milk”, “butter”, 10.45} as string
"breadmilkbutter10.45"

set AppleScript’s text item delimiters to {“, “}
{“bread”, “milk”, “butter”, 10.45} as string
returns this result:
The text item delimiters property can be used to extract individual names from a pathname. For example, the script
returns the result “Release Notes”.
If you change the text item delimiters property in Script Editor, it remains changed until you restore its previous value or until you quit Script Editor and launch it again. If you change text item delimiters in a script application, it remains changed in that application until you restore its previous value or until the script application quits; however, the delimiters are not changed in Script Editor or in other script applications you run.
Scripts commonly use an error handler to reset the text item delimiters property to its former value if an error occurs (for more on dealing with errors, see “AppleScript Error Handling” (page 40)):
"bread, milk, butter, 10.45”

set AppleScript’s text item delimiters to {”:“}
get last text item of “Hard Disk:CD Contents:Release Notes”
set savedDelimiters to AppleScript’s text item delimiters
try
set AppleScript’s text item delimiters to {”**"}
–other script statements…
–now reset the text item delimiters:
set AppleScript’s text item delimiters to savedDelimiters
on error m number n
–also reset text item delimiters in case of an error:
set AppleScript’s text item delimiters to savedDelimiters
–and resignal the error:
error m number n
end try

Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) mardi 4 août 21:26:33