I can make a manual prompt list but wondered if i could make a list from the contents of a folder.
This is what i would like to happen
A folder contains 1+ text files
I would like to generate a prompt list that reads this folder and inserts the filename in the list
When the user clicks the filename then it reads the details of the files and saves the information.
I can do most of this but am at a loss as to how to make the list in the ifrst place.
Do i read the folder as a list and then display the propmt?? as i can do that, but how do i set a variable that reads the choosen file??
You can use the magic command “list folder”.
This code assumes that there are only files in the folder, so you avoid trying to read a folder. If you are not sure, you can use instead “find”'s shell command, looking only for files and excluding directories (but that is another question):
set theFolder to alias "path:to:folder:"
choose from list (list folder theFolder)
if result ? false then read file ((theFolder as text) & result)
set filePath to choose folder
set thelist to list folder filePath
try
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to space
set thelist to text items of hidFiles as list
set AppleScript's text item delimiters to oldTIDs
on error
set AppleScript's text item delimiters to oldTIDs
end try
set theChosen to (choose from list thelist OK button name "OK" without multiple selections allowed and empty selection allowed)
if theChosen = false then return
set theChosen to (filePath as string) & theChosen as alias
set hello to read theChosen as list using delimiter return
display dialog hello
I have this and it works, is this the tidiest way to do it??
Greg!
Your code will allways throw an error, since hidFiles should be allways an undefined var (unless I’m missing something). What are you trying with the tid’s stuff? (I’m puzzled with this)
set filePath to choose folder
set thelist to list folder filePath
set theChosen to (choose from list thelist OK button name "OK" without multiple selections allowed and empty selection allowed)
if theChosen = false then return
set theChosen to (filePath as string) & theChosen as alias
set hello to read theChosen as list using delimiter return
display dialog hello
I have solved it. This snippet will read a folder and list in propmt box, when you choose 1 or more text files of format
hannehd,ajsuije,ajsia
i.e. a single line
It will read this line and return the value no matter how many files have been selected, have choosen max of 3 but works with that.
set filePath to choose folder
set thelist to list folder filePath
set fileList to {}
set theFiles to (choose from list thelist OK button name "OK" with multiple selections allowed and empty selection allowed)
if theFiles = false then return
set fileCount to count theFiles
repeat with i from 1 to fileCount
set theFile to (filePath as string) & item i of theFiles as alias
set theKeys to read theFile as string
copy theKeys to end of fileList
end repeat
display dialog fileList as string