And finally, building on the saved Automator Workflow that I named AskForFilesFolders.workflow, setting the Path automator variable, and returning selected files and folders as POSIX path list items:
set start_folder to "$HOME/Documents"
set alist to paragraphs of (do shell script "automator -D Path=" & start_folder & " $HOME/bin/AskForFilesFolders.workflow 2> /dev/null | ~/trmdls.awk")
-- expand the start_folder to absolute path
set abspath to (do shell script "printf '%s' " & start_folder)
-- test if alist was cancelled (empty) or same string as start_folder
-- because user clicked choose without a selection
if alist = {} or (alist as text) is equal to abspath then
log "User cancellation, or choose without selection."
return
else
log alist
end if
return
The trmdls.awk script is also something that I use to clean up the returned content from mdls too. This content does not go into the Script Editor but any decent text editor. Also, make it executable after you save it:
chmod +x ./trmdls.awk
trmdls.awk
#!/usr/bin/awk -f
#
# trmdls.awk
# Usage: mdls -name kMDItemFonts filename | trmdls.awk
# 1) one line to process. Print entire third field
NR == 1 && !/\(/ {print substr($0, index($0,$3))}
# 2) multiple lines. Skip first and last lines containing '(' and ')'
# Remove quotes and trailing ",". Remove leading/trailing whitespace,
NR > 2 {print l} {$1=$1}1 {gsub(/,$/, "");gsub(/"/, "");l=$0}
END {exit}