ask file "Save to" with type "text files|TXT"
put ".txt" after it
if it is empty then
break
end if
put field "Field1" into myText
open file it for write
write myText to file it
Close file it
ask file "Please select a name and location for this file..." with "Untitled.text"
if it is not empty then
put it into tmpFilePath
put field 1 into url("File:" & tmpFilePath)
end if
break
...
ask file "Save to" with type "text files|TXT"
put ".txt" after it
## Since you put something after IT, IT is of course never empty, so this:
if it is empty then
## does not make sense!
## break
## BREAK will exit a SWITCH structure, but you need to exit this handler.
## so BREAK will not work here
end if
...
You should get used to the shorter URL syntax, do like this:
...
ask file "Save to" with type "text files|TXT"
if IT = empty then
exit mouseup ## if this is inside a mouseup handler!
end if
## IT may change when you least exspect IT,
## so better put IT into another var immediately!
put it into tFileName
put ".txt" after tFileName
## Now the URL one-liner :-)
put field "Field1" into url("file:" & tFileName)
...
You don't need to close that. tFileName is only a variable holding 'it' in Klaus's example, 'it' is holding the path to the file your saving too.
Klaus wrote: Sat Mar 30, 2019 11:06 pm
## break ## BREAK will exit a SWITCH structure, but you need to exit this handler. ## so BREAK will not work here
Your example wasn't clear if you were using this inside of a menu item or not (I made the poor assumption you were using this inside a save or save as menu item). If this is inside a handler, such as mouseUp on a button, then Klaus's point is valid, you'd need an exit instead.