What duskwuff said: do it using public key authentication if your use case is actually an ssh login.
More generally, however, the difference between your working scenario and your non-working scenario is not whether it’s run from AppleScript Editor or from the terminal. It’s whether it’s run from the same window as the ssh command or a different window. You can make that script work in the terminal just as it does from AppleScript Editor by removing the if/else/endif so that the terminal (which always has a window open, at least while typing a command in a window, and thus never has a count of 0) opens a new terminal window just like AppleScript Editor does:
tell application "Terminal"
activate
set SSH to "ssh [email protected]"
do script SSH
end tell
(** etc. **)
The problem with “do script SSH in window 1” is that window 1 is the terminal that the script is running in. This means that the script has to complete in window 1 before window 1 can act on the commands it is given.
But by the time the script has completed, the password has already been keystroked in, and ssh doesn’t accept password data until it requests it. It’s likely you’ve seen similar things happen when manually logging in over slow connections. If you type the start of the password before ssh requests it, ssh ignores those characters.
I can think of one way around this problem if you’re willing to background the process. If you just add an ampersand to the end of the command, it goes into the background; this means that the terminal is now accepting input.
osascript ~/Desktop/ssh_dev.scpt&
This is a bit kludgy, because you can type into the terminal, too, and could easily type before the 2-second delay is up, preempting the text that is being keystroked in by the AppleScript. But it will work.
Similarly, if you’re not tied to using osascript and a text file, you could save the script as an application set to stay open, and then put the password injection into the idle handler. That’s getting pretty far afield of your requested conditions, however.
Another option might be to look into “expect” (use “man expect”). You should be able to construct an expect command line in AppleScript that will successfully provide the password to ssh, but that’s getting awfully complicated for this purpose.