Ok here is the problem. I am trying to write a script that reads/edits a pref file. After telling it a specific line, it then counts the number of words and subtracts it by 2 (i dont want the first two words). i know how to write to like a text field, but since the numbers could vary, i would have to put in (*stuff to write) & (*stuff to write) & (*stuff to write) & (*stuff to write), etc. So my main question to you is, how would i fix this script to the way i want it to work. i know its a bit confusing and if you need any clarification, let me know. Here is the script ive done so far
Or better yet, to make it easier here, it is in simpler terms
server=cool guy
name=joe
i want the words “cool guy” from the first paragraph, leaving off the server and =, or just start reading from the =
Not really sure if this is what you’re looking for, but as long as the lines in the pref file end with a return, then you can get the end of a “paragraph”. This may look a little strange but it should work. For the sake of this test, you’ll need a file called “x.txt” on the desktop which contains nothing except:
server=cool guy
name=joe
With a return at the end of the first line. Then try this:
Thats sorta what I need, but really all i need is to take all the text after the “=” and put it into a text box. If i remember correctly I think there is a command like “read file path:to:file before string “=”” or something like that? So in a nutshell, I need to get from point A to point B.
A- Server=cool guy
B-cool guy
with A being the origional text in a doc and B being the results of some string so i can do whatever i want with it (ex. put it in a text box)
OK, the script I posted before does that, but you’re second post made me do some digging and this can in fact be done much easier. You can’t read after a character or string, you can only read up to (and optionally including) a character/string, or you can pass the read command delimiters to break the text into a list, which is much less efficient in this case. So, assuming the variable myFile is an alias pointing to a file whose contents are:
Four lines and three are basically “clean up”. Much shorter than the previous script. Remember that a “paragraph” is created every time you press return. It doesn’t need a blank line, it just can’t be a “wrapped” continuation of the previous line. So every line in a preference file (that isn’t wrapped) is a paragraph.
I get in the dialog box “e” but in the results box i get “=” Seems its counting letters or something.
and in the first script you gave me, it returned “j=o=e”
Im confused :?
set myString to item 2 of paragraph 1 of (read file myFile)
to:
set myString to text item 2 of paragraph 1 of (read file myFile)
If I were you I would load the file into the script as a list of items:
set Prefs to read PrefsFile using delimiter ","
This would work with a text file set up with commas seperating the entries, so : “This=That,That=this” is loaded as {“This=That”,“That=this”}
You might also set up some sort of loop to load the data from your text file into a record for easier access.
works perfectly in script editor, however in xcode it dosent
that is what i was developing the script for my program for, but instead of returning the full word, it returns the letter. like when i say text item 1, it gives me the S from Server.
Dont know why it works in one app but not the other
Nevermind. I fixed it. Apparently it didn’t like the copy/paste, so I rewrote the part about the text item 1 by hand and that did the trick. Thank you so much for all of your help guys! I would have never been able to do this by myself.