Advice - Entering & storing information for later use in a script

I keep moving between using standard files & folders in the Finder, and using DevonThink. In my most recent move I moved from DT to F&F and was able to quickly set up some automation using Python (my preferred programming language). The move to F&F was largely motivated by that it simply was easier for me to set up some automation using Python since I have forgotten most of what I knew about AppleScript (I used to be pretty good at it).

Now I want to see if I can do the same thing inside DT using AppleScript, but I don’t know the best approach for how to do it. There are two scripts that I want to see if I can replicate, the first in pretty simple and shouldn’t be much of a problem. It’s basically asks for some info and then create a set of files and folders in a predefined place - the only problem should be the clumsiness of AppleScript when it comes to text handling. The second I don’t know the best way to implement.

What happens is that the first script, among the other files, creates one file that contains some basic data. Then I spend some time to find additional data that I manually fill in. In the second script I want to take the data from that file and create some additional files.

Here is how I want it to work with some imagined data: I run the first script which asks for some names - let’s say “Anna, Bertil, Cecilia” - and creates a file like this (Note: this is just an example format, this looks different in my Python solution)

first: Anna
last: 
email: 
phone: 

first: Bertil
last: 
email: 
phone: 

first: Cecilia
last: 
email: 
phone: 

I figure out what the missing data is and get something like this

first: Anna
last: Andersson
email: aa@example.com
phone: 123456

first: Bertil
last: Bo
email: bb@example.com
phone: 234561

first: Cecilia
last: Carlsson
email: cc@example.com
phone: 345612

I now want the second script to parse this data and create some additional files. But I don’t know the best way to store & retrieve data using AppleScript. In my Python solution I simple use the config module and store this data as a config file, i.e. a text file in a well defined format.

How would you solve this using AppleScript and DT (I would prefer a solution that uses text files but I’m open for other suggestions)

Your data seems to be clearly defined
Working with text files isn’t a problem

Creating the first file seems straightforward using Applescript

For the second file, I’m not seeing a problem using Applescript to parse each line and extract the data

Applescript has a text delimiter feature for auto parsing
The offset feature can be used to separate the labels from the data

May be the easiest approach would be to call a Python script from within AppleScript?
do script ... should do the job (hopefully).
Re-creating anything written in a modern programming language in AppleScript is probably quite tedious. Especially if you want to work with text.

I figure out what the missing data is and get something like this

You figure it out how?

parse this data and create some additional files.

  • Parse it how?
  • Create what kind of files with what data

I need to lookup the data in various systems we have at work, and then enter it manually in the “data file”. There is “no way” to automate this part, i.e. it would be too much work to do this and it wouldn’t be worth the effort (not to mention that there would probably be some security issues as well).

Parsing: in Python I use the config module to parse the “data file”, it’s fast, simple and solves my problem. Using AppleScript I don’t really know, so far the best way I can think of is repeated use of the “text items” feature. This is the part where I’m looking for advice.

What’s going to happen: using info from “data file” I want to create a couple of files that (assuming the data in the fictive example) contains names and email addresses. Basically, I want to use the name/email info to create documents based on various templates.

If your Python solution is working I wouldn’t bother with translating it to AppleScript.
Just use AppleScript to run the Python scripts.
There are over 800 posts on doing just that @MacScripter.

2 Likes