Hi Matt,
mattmaier wrote:Hey Klaus,
Thanks, that worked. The first time I tried to retype it all I got the same error, but I realized I was not putting "the" before "lastSavePath". Apparently that's important.
Yes, custom properties are addressed with a leading "THE XYZ of...", otherweise the engine thinks this is a variable!
mattmaier wrote:Why did you put "it" into "tFile" after the user closes the dialog?
Old habits!
I know today that IT changes when you least exspect it, so I NEVER use IT in more than one line!
mattmaier wrote:The "save" button never compiled, so I never got to check, but why would my original code be putting the field's contents into the custom property if I used the URL command?
Yep, with the keyword URL you are reading the content of files!
mattmaier wrote:So...it's mostly working. As long as the "save as" button is used once, and then only the "save" button is used from then on, it works correctly. If "save as" is used again, and you save over the existing file, it starts adding an extra ".txt" and actually creates new files. The very first time the user selects the destination folder and types in a file name, the path is just the file path and name without any extension. The second time, because the file already exists, the path includes the file extension (.txt).
Is there a command to capture the path without its file extension? Or do I have to deal with either case?
Well, check for the suffix before adding it!
Code: Select all
on mouseUp
ask file "Please name the file:"
put it into tFile
if tFile = empty then
exit mouseup
end if
### !!! ;-)
## Only store the PATH -> without "file:"! BEFORE ADDING THE SUFFIX
set lastSavePath of button "Save As" to tFile)
## Check if user added suffix:
if NOT tFile ends with ".txt" then
put ".txt" after tFile
end if
put field "Text" into URL ("file:" & tFile)
end mouseUp
on mouseUp
put the lastSavePath of button "Save As" into tFile
if NOT tFile ends with ".txt" then
put ".txt" after tFile
end if
put field "Text" into URL("file:" & tFile)
end mouseUp
Not sure if I understood your problem correctly however...
Best
Klaus