Sunday, June 13, 2021

#1 2021-06-06 01:48:41 pm

traegheitsmoment
Member
Registered: 2021-01-13
Posts: 43

Let AppleScript read out txt or csv file possible?

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

Offline

 

#2 2021-06-06 09:38:38 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 40

Re: Let AppleScript read out txt or csv file possible?

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).

Applescript:

-- 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

Offline

 

#3 2021-06-07 11:46:59 pm

traegheitsmoment
Member
Registered: 2021-01-13
Posts: 43

Re: Let AppleScript read out txt or csv file possible?

This is fantastic. Fits exactly my needs. Thank you very much, Mockman!

Offline

 

#4 2021-06-08 03:24:47 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 40

Re: Let AppleScript read out txt or csv file possible?

Glad it works for you.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)