At present, I have a very simple bash script which calls
osascript -e a bunch of times; it looks like this (newlines added for readability):
#!/bin/sh osascript \ -e 'tell application "Terminal" to activate' \ \ -e 'set allWindows to number of windows' \ -e 'set newTab to true' \ \ -e 'repeat with i from 1 to allWindows' \ -e ' set allTabs to number of tabs of window i' \ -e ' repeat with j from 1 to allTabs' \ -e ' if custom title of tab j of window i contains "Hi" then' \ -e ' set frontmost of window i to true' \ -e ' set selected of tab j of window i to true' \ -e ' set newTab to false' \ -e ' end if' \ -e ' end repeat' \ -e 'end repeat' \ \ -e 'if newTab then' \ -e ' tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \ -e ' tell application "Terminal"' \ -e ' do script ("tabname $2") in selected tab of the front window' \ -e ' set custom title of selected tab of the front window to "$2"' \ -e ' end tell' \ -e 'end if' \ \ -e 'tell application "Terminal" to do script ("$1") in selected tab of the front window'
The idea behind this is to let me call something like
~/term.sh pwd Hi to open a new terminal tab with the title "Hi" and call
pwd inside it.
The only problem is that it errors with
222:227: syntax error: Expected “then”, etc. but found identifier. (-2741). I assume this means an
if is missing a
then, but can't see any of those. The other thought I had is that 222:227 indicates columns, but again I don't see how those columns of the command are wrong.
Is there anyone who can point me in the right direction here please?