"do script" command stopped working!

Hi all,

I have written a simple script that makes use of the “do script” command to instruct the Terminal to telnet to my NAS server.

It all worked fine.

Then not. I was writing another script which also used “do script”, and it simply stopped working. If the script is executed, the Terminal will do everything it is told except “do script”'s: Launch, then quit when instructed.

The “do shell script” command still works, but in order to automate telnet, “do script” is the only trick I have found.

The other user on my machine does not have the same problem, “do script” still works. I have repaired permissions, but to no avail.

Any idea?

thanks a lot

I didn’t know there was a “do script” command. How does this differ from “do shell script”?

And would you mind posting your script here? I’m curious to see just how you’re telneting from the terminal.

hi et,

why don’t you post the code so we can all try it out? otherwise you are just asking for good guesses.

have you tried something like

osascript -e ‘beep’

I don’t know a lot about that myself, I just use it occasionally when I’m SSHing into somewhere. Maybe that could help. I think you need to put in a new “-e” at the start of every new line.

Thanks for the replies. I didn’t post the code as it was working (and still is if executed by the other user on my machine) not 2 days ago.

But there you go:

if button returned of (display dialog "Ejecter les disks & éteindre le serveur?" buttons {"oui", "non"} default button 2 with icon caution with title "éteindre le serveur") is "oui" then
	
	set MyUsrName to the text returned of (display dialog "Please enter your NASLite admin username:" default answer "")
	set MyPass to the text returned of (display dialog "Please enter your NASLite password:" default answer "")
	
	tell application "Finder"
		repeat with i from 1 to 3
			set MyDisk to "Disk-" & i as string
			if disk MyDisk exists then
				eject disk MyDisk
			end if
		end repeat
	end tell
	
	tell application "Terminal"
		activate
		do script "telnet 192.168.0.20" in front window
		delay 5
		do script MyUsrName in front window
		do script MyPass in front window
		do script "8" in front window
		do script "y" in front window
		delay 2
		quit
	end tell
end if

The difference between “do shell script” and “do script” is the former sends unix script to the system without launching the Terminal. The latter works a bit like “System Events”, it basically tells the Terminal to enter a line of text and press Enter. That is why you need to specify in which window the script should be entered.

@ Lambo
I’m a bit confused: where do you suggest I add this extra “-e”? it cannot be added after or before “do script”.

I revived an old iBook g3 as the g5 will be taken away soon. I copied the above script into my newly created ~/Library/Script folder… And same problem.

When reaching ‘Tell application “Terminal”’, the Terminal activates, stays open 7 seconds (as there are 2 ‘delay’ commands, 5 seconds and later 2 seconds), and quits, doing absolutely nothing else.

Can I just point out this is the exact same script (word for word) that was working on the g5 2 days ago, and is still working on the g5 when launched by the second user. Isn’t that a bug from space or what??

Oh, and btw, below is the script I was writing when the ‘do script’ stopped working. I was using it instead of the ‘do shell script’:


-- This script deletes in ~/Music/iTunes the symbolic link to the iTunes Library stored on the NAS server and creates a new one.

if button returned of (display dialog "Rebiduler iTunes pour que ça remarche?" buttons {"Yes", "No"} default button 1 with icon caution with title "iTunes ne marche plus") is "yes" then
	
	tell application "Finder"
		
		if disk "Disk-1" exists then
			
			set MyLibrary to "Disk-1:iTunes" as alias
			set myscript to URL of MyLibrary
			set myscript to characters 17 through end of myscript as string
			set myscript to "ln -s " & myscript & "iTunes\\ Library ~/Music/iTunes/" as string
			
			try
				do shell script "rm ~/Music/iTunes/iTunes\\ Library"
			end try
			do shell script myscript
			
		else
			display dialog "Le Disk-1 n'est pas connecté...
			
			1. s'assurer que le serveur est allumé
			2. lancer l'application \"disk 1\" pour se connecter" with title "iTunes ne marche plus"
			
		end if
	end tell
end if

Sorry etien, it was early in the morning, and I got your question the wrong way round. You can forget about “osascript”. It’s for doing applescripts from the terminal, not doing shell scripts from applescript.

hi et,

this works for me. could it be that you are on a different version of OS X now (and thus a different version of AppleScript)?

i’m using 10.4.5, and although i did need to tweak the script a bit (for some reason the telnet on our Solaris box needs to be told explicity what the username is from the command line) it runs fine. of course it gives me errors on commands, ‘8’, and ‘y’, but that is to be expected. here is the changed code:

if button returned of (display dialog "Ejecter les disks & éteindre le serveur?" buttons {"oui", "non"} default button 2 with icon caution with title "éteindre le serveur") is "oui" then
	
	set MyUsrName to the text returned of (display dialog "Please enter your NASLite admin username:" default answer "")
	set MyPass to the text returned of (display dialog "Please enter your NASLite password:" default answer "")
	
	tell application "Finder"
		repeat with i from 1 to 3
			set MyDisk to "Disk-" & i as string
			if disk MyDisk exists then
				eject disk MyDisk
			end if
		end repeat
	end tell
	
	tell application "Terminal"
		activate
		do script "telnet -l" & MyUsrName & " 192.168.0.20" in front window
		delay 5
		do script MyPass in front window
		delay 5
		do script "8" in front window
		do script "y" in front window
		delay 2
		quit
	end tell
end if

hth

Solved.

I simply trashed the com.apple.Terminal.plist situated in ~/Library/Preferences. It worked. It is a great shame I did not think of this earlier. Don’t know why, simply assumed Terminal didn’t have its own plist!

The fact that it worked with the other user should have been a hint, too, that something was amiss in my own prefs folder.

Thanks a lot for trying anyway!

arg

Spoke too fast. Trashing the plist worked on the G5, but not on the iBook G3.

I tried to replace do script “<>” in front window with do script with command “<>” in front window, and although it did get the Terminal to execute the command, it also opened a new window for each new command, which is obviously useless!

Is that normal behaviour in your experience?

‘do script’ stopped working again on the g5.

Has anyone ever seen things like this happen?

hi there

sorry to bump my own topic, but I thought I’d just check anyone who might’ve missed this sees it.

Still a mystery. I’ve tried trashing any pref file that just might have any remote relation to applescript.

No effect. Which is even weirder considering trashing the com.apple.Terminal.plist worked the first time, but not the times after that!

Since then, I’ve recloned my system from another partition on which the command worked. Worked 1 day that is, then the command stopped working again.

Obviously a corruption finds its way into my system and targets this command specifically, but I am yet to find where it might come from.

What I’d like for a start though, is to find at least one person in the whole mac world with a similar problem! I have asked everywhere, noone has ever seen this happen.

So as I’ve said before, any comment very much appreciated.