Hi to all the great mascripters, i am trying to realize a script that retrieves a word randomly from a text file and use this in a keyboard maestro macro, the file is made of lines with one word each, is saved in UTF, here is the code that a friend from macscripter.net sent me but it is not working because of a thing that surely I don’t know.
following the code:
set fileLoc to (Users/minipower/Documents/testnomi.txt)
set nameText to read fileLoc
set tNames to paragraphs of nameText
set oneName to some text of tNames
and of course the error:
script error: Expected “,” but found unknown token. (-2741)
set fileLoc to ((path to documents folder as text) & "testnomi.txt") -- relative path to the plain text file
set nameText to read file fileLoc
set oneName to some paragraph of nameText
or
set oneName to some item of (read file ((path to documents folder as text) & "testnomi.txt") using delimiter linefeed) -- or return
if the line separator is return (ASCII 13) change linefeed to return
Thank you for your fast reply and help but i tried both solutions and they are not working, can you please insert my path into your example?
with this:
set oneName to some item of (read file ((Users/minipower/Desktop/) & “testnomi.txt”) using delimiter return)
i obtain this error:
script error: Expected expression but found “)”. (-2741)
with this:
set fileLoc to ((/Users/minipower/Desktop) & “testnomi.txt”) – relative path to the plain text file
set nameText to read file fileLoc
set oneName to some paragraph of nameText
i obtain this:
script error: Expected expression, “)”, etc. but found “/”. (-2741)
Thank you very much, it is working like a charm now, i always used windows and this kind of things are different there, completely, i am not a programmer but i had to do something with it in simple way and this is disarming because i could never imagine it was so simple as putting only the name of the predetermined folder.
You were a great help