Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Help me troubleshoot

edited May 2010 in FastScripts
I have a script that activates, create a new window before it creates 3 new tabs (for 4 tabs in total) that ssh to a remote server at work. I use it on two different users (independent me and work me) on different Macs. The scripts are on Dropbox, so that they are synchronized to all the computers and users.

But for one user the script doesn't work until I allready have created a tab and logged into the remote server. I only get the following error.

Error Number:Can’t get text 1 thru 19 of \"bash — bash\".

The script in question:

-- `menu_click`, by Jacob Rus, September 2006
-- Accepts a list of form: `{\"Finder\", \"View\", \"Arrange By\", \"Date\"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.

on menu_click(mList)
local appName, topMenu, r

-- Validate our input
if mList's length < 3 then error \"Menu list is not long enough\"

-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)

-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application \"System Events\" to my menu_click_recurse(r, ((process appName)'s (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click

on menu_click_recurse(mList, parentObject)
local f, r

-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)

-- either actually click the menu item, or recurse again
tell application \"System Events\"
if mList's length is 1 then
click parentObject's menu item f
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse

-- Matthew Lambie, November 2007

-- Opens a Terminal with four tabs that then each reconnect to named screen
-- sessions or if that window is already opened, reapply focus

global window_id
global window_name
set window_id to 0
set window_name to \"\"
set user to \"tsd\"
set server to \"<servername>\"
set user_at to user & \"@\" & server

tell application \"Terminal\"

-- get every window id
set w_ids to (id of every window)

-- with each window id...
repeat with w_id in w_ids

-- have we found our target window_id?
if window_id is equal to 0 then

-- load this window's name
set w_name to name of window id w_id

-- is this the window we're looking for?
if (text 1 thru (count user_at) of w_name) is equal to user_at then
set window_id to w_id
set window_name to name of window id window_id
end if
end if
end repeat

-- if we have a window_id then we can give that window
-- the focus, otherwise we need to make a new window
-- with four tabs and execute the ssh/screen command in
-- each of those four tab

if (window_id is not equal to 0) then
-- give that window the focus
set frontmost of window id window_id to true

-- make a new window with the execution of a trivial command
do script \"clear\"

-- load up the window id of the window we just created
set window_id to id of first window whose frontmost is true

-- make tabs 2, 3 and 4
repeat with i from 1 to 3
my menu_click({\"Terminal\", \"Shell\", \"New Tab\", \"Ocean\"})
end repeat

-- for each of the four tabs we've now made
repeat with i from 1 to 4

-- build the command, then execute it
-- set cmd to \"clear; ssh -t \" & server & \" 'screen -d -R tfg_\" & i & \"'\"
set cmd to \"janus\"
do script cmd in tab i of window id window_id of application \"Terminal\"

end repeat
end if
end tell

It is a script that I have found on the Internet and edited to fit with my need, the original parts are in the script commented.


  • Hi there - I'm guessing the issue is in the line:

    if (text 1 thru (count user_at) of w_name) is equal to user_at then

    The problem with this line is it assumes the title of the window will be at least as long as the user_at string… if it's not, then it will fail.

    For example, most of your users probably have longer window titles because they show extra information. But the user for whom it is failing probably has turned off some title display options in Terminal preferences, under "Settings".

    If I understand the intent of this line, I think you can simplify the script and fix the issue by replacing the problematic line with:

    if (w_name contains user_at) then

    Hope this helps,

  • Thanks, that did it. I see now that my Window setting for the profile was different on that user. I really should starting reading the Soghoian/Cheeseman book.
Sign In or Register to comment.