Return a list of aliases from a list of posix paths, fast

Hello.

I haven timed the handlers below, I just perceive that this must be the fastest way to do it.

I have made those handlers, to work with mdfind, -why slow down during the conversion to aliases, when the search went so fast.

I also perceive that you want to try those handlers, so driver code is included in the library, you’ll have to comment it out before using it.

It is designed for mdfind, so it needs reworking to be used with anything else than the boot volume. I have assumed that the only volume you have indexed for Spotlight is the boot volume.

If this doesn’t suit you, feel free to rework the code, so that you can supply another volume name to
hfsFromMDFindText.

# http://macscripter.net/viewtopic.php?pid=178384#p178384
use AppleScript version "2.3"
use scripting additions

(* Driver code *)
set theFolder to getPxFolder()

set mdfindFlist to (do shell script "mdfind -onlyin " & quoted form of theFolder & " 'kMDItemFSName = \"*txt\"' ")
log "Paths returned from mdfind (.txt) files."
log mdfindFlist
if mdfindFlist is "" then return
set hfsList to hfsFromMDFindText(mdfindFlist)
log "
Hfs paths, returned from posix paths "
log hfsList

set aliasList to makeAliasList(hfsList)
if aliasList is {} then return
log "
aliases: list "
log aliasList
log "item 1 of alias List :"
log item 1 of aliasList
log " class of item 1 of alias list  " & (class of item 1 of aliasList)
log "
item 2 of aliaslist"
log item 2 of aliasList
log "name of item 2 of aliaslist"
tell application id "sevs"
	set f to name of (item 2 of aliasList)
end tell
log "its name is: " & f

return

script o
	property m : missing value
end script
on getPxFolder()
	if o's m is missing value then
		tell current application
			set o's m to POSIX path of (choose folder)
		end tell
	end if
	return o's m
end getPxFolder
(* End of driver code *)

on getBootVolume()
	tell application id "sevs"
		set sdsk to name of startup disk
	end tell
	return sdsk
end getBootVolume


on hfsFromMDFindText(pxFlist)
	-- Assumptions: that the files are from the boot volume
	-- We fix any ':' interspersed in the filenames first!
	set bootD to getBootVolume()
	set astid to text item delimiters
	
	set text item delimiters to (return & linefeed)
	set pxFlist to linefeed & (paragraphs of pxFlist) & return -- coerces to text
	-- so we can differentiate between the start and ends of the items
	
	set pxFlist to pxFlist as text
	
	set text item delimiters to linefeed
	set tmpItems to text items of pxFlist
	
	set text item delimiters to ("\"" & bootD) --we fix up the start of txt items.
	-- set text item delimiters to bootD --we fix up the start of txt items.
	set pxFlist to tmpItems as text
	
	set text item delimiters to return
	set tmpItems to text items of pxFlist
	set text item delimiters to ("\"" & return) -- and takes care of the end.
	set theList to tmpItems as text
	
	-- fixes ':' in pxFileNames 
	set text item delimiters to ":"
	set tmpItems to text items of theList
	set text item delimiters to character id 0 -- Can't be in a valid filename!
	set theList to tmpItems as text
	-- time to turn the '/' into ':'
	set text item delimiters to "/"
	set tmpItems to text items of theList
	set text item delimiters to ":"
	set theList to tmpItems as text
	-- time to remove those pesky nulls 
	set text item delimiters to character id 0 -- Can't be in a valid filename!
	set tmpItems to text items of theList
	set text item delimiters to "/" -- we turn them into '/'
	set theList to tmpItems as text
	set text item delimiters to astid
	
	return paragraphs 1 thru -2 of theList
end hfsFromMDFindText

on makeAliasList(theList)
	set astid to text item delimiters
	set text item delimiters to (return & linefeed)
	set theList to linefeed & (items of theList) & return -- coerces to text
	-- so we can differentiate between the start and ends of the items
	
	set theList to theList as text
	
	set text item delimiters to linefeed
	set tmpItems to text items of theList
	
	set text item delimiters to "file " --we fix up the start of txt items.
	set theList to tmpItems as text
	
	set text item delimiters to return
	set tmpItems to text items of theList
	set text item delimiters to " as alias," -- and takes care of the end.
	set theList to tmpItems as text
	
	set text item delimiters to astid
	
	return (run script ("{" & (text 1 thru -2 of theList) & "}"))
end makeAliasList


Edit
I have added that it is designed for mdfind, so it needs reworking to be used with anything else than the boot volume.