-1
set listOfjellybeans to {}
set popcorn to paragraphs of (read file "Macintosh HD:Users:whomever:Desktop:Test_INDIGO.txt")
repeat with nextLine in popcorn
    if length of nextLine is greater than 0 then
        copy nextLine to the end of listOfjellybeans
    end if
end repeat
choose from list listOfjellybeans

Edit

This does more along the lines of what I asked in my original post. It writes the text in the text file to a list and then outputs it to a dialog box. I still have steps to complete for my idea of a script that writes a script but thanks to red_menace I got a better understanding of arrays and lists and how to automate the creation of them more quickly. The real problem statement has more than 8,000 variables.

Here is an example file and when you save it to the desktop and change the path in the example, a dialog box should appear listing a column of the text values.

https://docs.google.com/document/d/1KwLVbnhqXrJlRxIYie3uvKYn5DkU7LsLTNS6E0dBWsQ/edit

TOKI
  • 33
  • 11
  • 1
    You can’t dynamically create variables (or handlers) like that in AppleScript - they need to be declared at compile time. Just use a list and pass the items to a handler instead of trying to automate the creation of 4500 pieces of code that do essentially the same thing. – red_menace Mar 17 '21 at 14:07
  • Thanks for the reply. Not really sure what you mean with your comment. How do I "use a list and pass the items to a handler"? Sorry, I'm pretty unaware of the vocabulary of how to do most things in coding. – TOKI Mar 17 '21 at 14:20
  • Can you provide an example of a text file to use and the expected output? – red_menace Mar 17 '21 at 14:37
  • well that helped greatly. But not sure where to go now. I set the dummy example in the original post. I can provide an example .txt file I suppose. – TOKI Mar 17 '21 at 14:51
  • You mentioned reading items from a file and using them to replace items in a template - can you give an example of the template file and the expected output (e.g. what are you using as placeholders, are you replacing only once, etc)? – red_menace Mar 17 '21 at 15:05
  • It would also help to use repositories that do not require a membership, or place your items in the topic to avoid future issues such as broken links. – red_menace Mar 17 '21 at 15:29
  • Well it will take me time write up an example of what I want to do that isn't just the project I'm working on, begging for help. – TOKI Mar 17 '21 at 16:16
  • I'm not sure what you mean by "repositories that do not require membership". Are you talking about the GitHub page I set up? I'm pretty Laissez-faire about managing projects and this is a hobby, not really expecting it to go anywhere. Or are you talking about the google drive link? I'm confrused. Sorry, new to stackoverflow and how to go about freelance code writing in general. – TOKI Mar 17 '21 at 16:21
  • I don't know how to post a .txt file without it being from a hosting body like google or dropbox – TOKI Mar 17 '21 at 16:23
  • I'm still not quite understanding what you are trying to do. Are you wanting to read a list of items from a file, then use those items to replace placeholder text in another text file? – red_menace Mar 17 '21 at 20:25

1 Answers1

-1
set ListOfVariables to {}
set VariableBlock to paragraphs of (read file "Macintosh HD:Users:whomever:Desktop:Test.txt")
repeat with nextLine in VariableBlock
    if length of nextLine is greater than 0 then
        copy nextLine to the end of ListOfVariables
    end if
end repeat
set textFile to "/Users/whomever/Desktop/BATTERY.txt"
set PropertyVariables to "property eGrepœ1 :  µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{2},ΩΩd{3}.ΩΩd{2}µ
property eGrepœ2 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{2},ΩΩd{3}.ΩΩd{2}µ
property eGrepœ3 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1},ΩΩd{3}.ΩΩd{2}µ
property eGrepœ4 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{3}.ΩΩd{2}µ
property eGrepœ5 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{2}.ΩΩd{2}µ
property eGrepœ6 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1}.ΩΩd{2}µ
property eGrepœ7 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1}.ΩΩd{1}µ
property eGrepœ8 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1}.ΩΩd{3}µ
property eGrepœ9 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1}.ΩΩd{4}µ
property eGrepœ10 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1}.ΩΩd{5}µ
property eGrepœ11 : µpriceValue___11gHJΩµ>ΩΩ$ΩΩd{1}.ΩΩd{6}µ

"
set BlankPropertyVariables to "property current®Price : missing value

"
repeat with theItem in ListOfVariables
    set findText1 to "œ"
    set replaceText1 to theItem
    set newText1 to do shell script "sed 's|" & quoted form of findText1 & ¬
        "|" & quoted form of replaceText1 & "|g' <<< " & quoted form of PropertyVariables
    do shell script "echo  " & quoted form of newText1 & " >>  " & quoted form of textFile
end repeat
repeat with theItem in ListOfVariables
    set findText2 to "®"
    set replaceText2 to theItem
    set newText2 to do shell script "sed 's|" & quoted form of findText2 & ¬
        "|" & quoted form of replaceText2 & "|g' <<< " & quoted form of BlankPropertyVariables
    do shell script "echo  " & quoted form of newText2 & " >>  " & quoted form of textFile
end repeat
set IdleLoop1 to "on idle
    getPrices()
    set {year:y, month:m, day:d} to (current date)
    tell application µMicrosoft Excelµ
        open µ/Users/clusterflux/Desktop/人MASTER人_excel.xlsxµ
        set display alerts to false
        first row index of (get end (last cell of column 2) direction toward the top)
        set LastRowCrypto to first row index of (get end (last cell of column 2) direction toward the top)
        set value of cell (µBµ & LastRowCrypto + 1) to y
        set value of cell (µCµ & LastRowCrypto + 1) to (µ=TODAY()µ)
        set value of cell (µDµ & LastRowCrypto + 1) to d
        set value of cell (µEµ & LastRowCrypto + 1) to (time string of (current date))"
do shell script "echo  " & quoted form of IdleLoop1 & " >>  " & quoted form of textFile

This is part of the way on what I'm talking about. It doesn't currently work on my machine but it should work by writing a large text file saved to the desktop. The generated text file will still need to be modified slightly because of syntax but it's a simple find/replace all for the placeholders. It took a lot of brain squishing but it saved me copy and pasting it like an idiot.

TOKI
  • 33
  • 11
  • If anybody knows how to fix an error I'm encountering, I can't create a new file and write to a text file. `Do shell script` doesn't work, `write text to textFile` doesn't work, `set textFile to /path/TEST.txt` doesn't create a file on the desktop like it used to. Someone suggested `do shell script "touch "` and that creates the file but I can't write to it. – TOKI Mar 19 '21 at 09:18
  • As mentioned in comments to some of your other topics, you need to use `open for access` if using AppleScript to write to a file, and you need to escape quotes and the escape character (\) when using them inside a string. I still don’t know why you are trying to paste together a giant script using repeated copies of a template instead of using handlers - you are making this way more complicated than it needs to be, but constantly changing the question makes it hard to answer. – red_menace Mar 19 '21 at 14:34