Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread Display Modes
Old Jun 28, 2010, 06:35 AM   #1
macrumors newbie
Join Date: Jun 2010
AppleScript to launch console in terminal mode, not launching terminal

For the past couple of days I have been constructing a script to automate connecting to switches via terminal. A couple months back i stumbled over the screen command, and its ability to run on serial ports in order to grant console access to Nortel and Cisco switches. I have tried making several different scripts to get this work. First I tried with shell scripting, which worked most of the time. I would however come across the issue where if i did not close the screen correctly i would be left with a detached screen. This was easily enough fixed with unplugging and re-plugging in the usb to serial dongle.

It was at that point that I decided to step it up and try making an automated applescript to auto detect and pass the usb port info to the script and make it so you can unplug and move ports and re-run the script. Essentially making things much more streamlined. However when i run it i am getting:

error number -10004
as well as error
error "Must be connected to a terminal." number 1

Below is the script i have constructed, it is copied verbatim from my script window. Any input on this would be greatly appreciated, as a note this is my first applescript, so if I am doing something nubish, please let me know so I can correct it in the future.

(*First step in, to find if you know what port your dongle is in*)
display dialog "Would you like to run the Terminal Console Launcher?" buttons {"Yes", "No"}
set theButton1 to button returned of result (*variable call, theButton1*)
if theButton1 = "Yes" then
	--Second Step in
	display dialog "Would you like to run the command to find your device now?" buttons {"Yes", "No"}
	set theButton3 to button returned of result (*Variable call, theButton3*)
	if theButton3 = "Yes" then
		do shell script "whoami > /User.txt" --finds the user name on the machine
		set unixPath1 to "/User.txt" --appoints pathing for the user store
		set openAndRead1 to (open for access (POSIX file unixPath1)) --opens and reads the text
		set user1 to (read openAndRead1 for (get eof openAndRead1)) --reads and sets to user1
		close access openAndRead1 --close the read to text, prevents memory leak
		do shell script "rm /User.txt" --removes the file to pipe in text
		do shell script "echo " & user1 (*debug catcher*)
		do shell script "ls -l /dev/tty.* > /Temp.txt" --pipes command to check dongle name
		set unixPath to "/Temp.txt" --appoints pathing to file for saving
		set openAndRead to (open for access (POSIX file unixPath)) --opens and reas text
		set txt to (read openAndRead for (get eof openAndRead)) --read file, set to txt
		close access openAndRead --closes text read, prevent memory leak
		do shell script "rm /Temp.txt" --removes file created above to pipe in text
		(*return txt*)
		set txt3 to word 44 of txt as string --captures needed info,1st entry
		set txt2 to word 45 of txt as string --captures needed info,2nd entry
		set txt1 to word 46 of txt as string --captures needed info,3rd entry
		do shell script "echo " & txt3 (*debug catcher*)
		set consolePath to "/" & txt3 & "/" & txt2 & "-" & txt1 as string --configures text output
		do shell script "echo " & consolePath (*Debug Catcher*)
		--set user2 to (display dialog "Enter you user name:" default answer "")
		--set password1 to (display dialog "Please enter your sys password:" default answer "")
		(*This is the binding command to launch the temrinal to the switch*)
		tell application "Terminal"
			do shell script "
			screen -x " & consolePath & " 9600" 
			--user name "" password "" with administrator privileges
			--sudo screen -s " & consolePath & " 9600"
			--possibly look into calling the new shell call here for force it run?
		end tell
		--screen -R " & consolePath & " 9600" user name user2 password "" with administrator privileges
		--do shell script "screen -D -R 3189"
	end if
else (*un-needed garbage collector call to end loop on alternate option call*)
	try (*Garbage collector*)
	on error the error_message number the error_number
		display dialog "Error: " & the error_number & ". " & the error_message buttons {"Cancel"} default button 1
	end try
end if
unholyrattrap is offline   0 Reply With Quote

MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Confusing Console and Terminal entries maddux530 OS X Mavericks (10.9) 2 Apr 28, 2014 10:18 AM
How to create an applescript for multiple dd terminal commands in sequence ? AlbertoBC Mac Programming 2 Feb 2, 2014 01:30 PM
Applescript to make terminal close automatically? Ri-dog Mac Programming 1 Jan 18, 2013 12:53 PM
Mac console/terminal usage lugaru Mac Basics and Help 5 Nov 26, 2012 08:39 AM
applescript leaves terminal window open Zeke D Mac Programming 6 Jul 22, 2012 02:44 PM

Forum Jump

All times are GMT -5. The time now is 11:46 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2015, MacRumors.com, LLC