Save a Text Edit document to a path with variables in Applescript
Hello, I'm working on a script to transfer data from my camera's memory card to my hard drive automatically. Basically I'm making my own version of the popular app ShotPut Pro because I don't want to pay for it! I have the entire script done and it works beautifully except for saving a log file. I am able to get my log constructed in a TextEdit document but I am having all kinds of trouble saving the file. I copied the part of the script responsible for logging below so you can see the problem. I'll do the best I can to explain the process.
The data is copied in 4 stages. First, the script creates a folder with today's date and a user inputted name (for example, a folder could be named "2012_7_1 (Summer Vacation)". After the folder is created, the script duplicates the "100CANON" folder from the memory card into the new dated and named folder on my hard drive. Once the duplication is complete, it verifies the copy by comparing the size of the original folder and the copied folder. In the final step, the script asks if I want to reformat my memory card (deleting the 100CANON folder, enptying the trash, and recreating a new 100CANON folder) and eject it or just leave it with the files on. After each stpe, a corresponding variable is given a number 0 or 1 depending on the option chosen.
When the log is created, it simple puts together the 4 log entry variables and sets that as the text in a new text edit document. Now I need to save the document in the folder I created (the "2012_7_1 (Summer Vacation)" folder). In the last line of the script, you see the variable "fname". That is the Folder Name variable that was defined by the user and it is the same variable that was used to create the folder.
Now for the problem. It saves the log in the root of "Macintosh HD". What's even more strange is that the name of the text file is the path I want it to save to. I've tried every variation I can think of, resulting in errors telling my I cannot save the file with the format "log" (I tried to make the file named log when I saved) and things like that. I also tried doing the entire save process using system events keystroked only to realize I could not find a way to navigate to the right colfer using the keystrokes only. Please help me streamline this and get the files to save in the right folder, thanks!
Here is the excerpt of the script:
if cgood = 1 then set entry0 to "Successful transfer. "
if cgood = 0 then set entry0 to "Failed transfer. "
if samename = 0 then set entry1 to " The folder was given a unique name. "
if samename = 1 then set entry1 to " The folder was given a name that already existed. The name was then changed by the user to a unique name. "
if slasherror = 0 then set entry2 to "The folder was given a name that does not contain /. "
if slasherror = 1 then set entry2 to "The folder was given a name that contained /. The folder was renamed by the user so that it did not contain /. "
if frmtd = 0 then set entry3 to "The card was not formatted or automatically ejected."
if frmtd = 1 then set entry3 to "The card was automatically formatted then ejected."
set logtype to (current date) & fname & entry0 & entry1 & entry2 & entry3
tell application "TextEdit"
activate
makenewdocument
set text of document 1 to logtype as text
save document 1 in file ("Macintosh HD/Users/StevePorter/Pictures/Canon EOS T1i/" & fname)
end tell
iMac, Mac OS X (10.6.8)