Hi there,
I’m currently trying to put together a fairly basic AppleScript Studio application in Xcode but I’ve run into a few problems with repeating the script.
Basically I’m trying to write a simple app with one main window with a box for text input and a button beneath, that when clicked, takes the information in the text box and puts it into a TextEdit document and saves that document.
So far I’ve built the interface and linked it to the script, and I’ve got the script to transfer the info from the text box into a textedit doc and bring up a save as box. It currently looks like this:
on clicked theObject
tell window of theObject
set paragraph 1 of document of application "TextEdit" to contents of text field "name"
end tell
tell window of theObject
delete contents of text field "name"
end tell
tell document of application "TextEdit"
save as "Document 1"
end tell
end clicked
The problem I’m having is that I would like the script to tell TextEdit that for each click of the button in my app, it should take the new information in the text box and put it in the next paragraph in the TextEdit document.
In other words, I want the script to be able to do the following: The first word is typed into the textbox, button clicked, which enters this word into paragraph 1 of the TextEdit document and deletes the text in the text box (this is already working). Then when a second word is typed into the text box and the button clicked, this word will be entered on the second line of the text edit document, and so on - But unfortunately I really don’t know how to do this (I’m rather new to applescript). Currently the script will just replace paragraph 1 of the textedit document when a second word is entered into the text box and clicked.
I’m really open to any suggestion of a way to script the app so that it knows to put each new entry in the text box onto the next line in the textedit document - I’ve just suggesting basing it off the number of clicks as I couldn’t really think of any other way to do it off the top of my head! I’ve done quite a lot of reading and searching but I haven’t been able to figure out how to do this.
The other question I have is whether I can make TextEdit automatically save a document with a name that I specify in the script when it opens? (Currently it brings up a save as dialog).
Many thanks in advance for the assistance, I spent all of last night just reading Applescript manuals to get to where I am now, and I’m really stuck on this at the moment.
Regards,
Mac_guy