Hi there,
inspired by the great work of the forum members I was wondering if it was possible to let Apple Script read out txt or csv files.
The idea is to make a simple table to tell AppleScript the path where to move files from a watched folder to another folder of an external server.
For example:
xxx volumes/data/folder abc
yyy volumes/data/folder def
zzz volumes/data/folder ghi
…
Of course I could simply integrate the data into the script itself. But I’d prefer to have it in an external file for more convenient maintenance of the data.
Does anybody know if this was possible and maybe has a link to some sort of example?
Thanks to you
traegheitsmoment
Here is a simple script which reads a tab-delimited text file, let’s you choose the code on the left and then returns the path on the right. You’ll have to change those clumps of spaces into tabs (or change the script to work with clumps of spaces).
-- Read file for codes and paths
set cdTx to read (choose file)
set dCod to {} -- list of codes
set dPat to {} -- list of paths
repeat with x in paragraphs of cdTx
set AppleScript's text item delimiters to tab
set end of dCod to text item 1 of x
set end of dPat to text item 2 of x
end repeat
-- equivalence -->
-- set dCod to {"xxx", "yyy", "zzz"}
-- set dPat to {"volumes/data/folder abc", "volumes/data/folder def", "volumes/data/folder ghi"}
-- Choose code and acquire related path
set cd to (choose from list dCod) as text
repeat with x from 1 to length of dCod
if (item x of dCod) is cd then
set chPat to item x of dPat
exit repeat
end if
end repeat
chPat
This is fantastic. Fits exactly my needs. Thank you very much, Mockman!