Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use iTerm With OnMyCommand Apps
I use OnMyCommand extensively, and most of my commands execute silently (the Terminal isn't used). There are some, however (top -u, for instance), that must be executed in the terminal.

Problem: I prefer iTerm to Terminal.app, but OnMyCommand sends everything to Terminal.app.

Solution: iTerm's extensive AppleScriptability. Using OMCEdit, you can modifiy any command that executes in Terminal.app to execute in iTerm instead. Just use the following code:

osascript -e 'tell app "iTerm"' -e 'activate' -e 'set myterm to (make new terminal)' -e 'tell myterm' -e 'set mysession to (make new session at the end of sessions)' -e 'tell mysession' -e 'exec command "/bin/tcsh"' -e 'write text "INSERT SHELL COMMAND HERE"' -e 'end tell' -e 'end tell' -e 'end tell'

Replace INSERT SHELL COMMAND HERE with your command (top -u, for instance). You can also use any of OnMyCommand's objects (cd __OBJ_PATH__; ls -la, for instance).

One final thing to note: Make sure to set Execution Mode to "silent"; otherwise, a Terminal.app window will open to process the osascript, thereby defeating the whole point of this hint.
    •    
  • Currently 2.25 / 5
  You rated: 1 / 5 (4 votes cast)
 
[23,150 views]  

Use iTerm With OnMyCommand | 8 comments | Create New Account
Click here to return to the 'Use iTerm With OnMyCommand' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use iTerm With OnMyCommand
Authored by: vxbush on Jun 12, '03 02:28:01PM

Question: ExecutiveEditor wrote:

One final thing to note: Make sure to set Execution Mode to "silent"; otherwise, a Terminal.app window will open to process the osascript, thereby defeating the whole point of this hint.

How the heck are you supposed to do this? I can't find anything within iTerm that tells me how to do this, or any command line option. I've got this problem with another script I've written.

---
--
Hey, don't look at me. I'm not responsible.

[ Reply to This | # ]

It's an OnMyCommand setting
Authored by: jecwobble on Jun 12, '03 05:06:56PM
The Execution Mode is a setting for an individual command in the OnMyCommand XML command list. It can either be set with a text editor, or with OMCEdit.

[ Reply to This | # ]
Two observations
Authored by: macubergeek on Jun 13, '03 09:15:35AM

Ok two observations, one somewhat obvious and one not so obvious.
1. the best way to copy an past this script from the macosx hints webpage is to paste it into a Tex-Edit new document and then use tools menu to change the formatting Mac -> Unix.
do chmod 700 filename and yer done.

2. This script is a good example of how somethings are easier done in shell rather than applescript.
Here's how do do this same script in shell (assumes you have apple's X11 installed):

xterm -e yourcommand
ie:
xterm -e top -u



[ Reply to This | # ]
Yes, except...
Authored by: ExecutiveEditor on Jun 13, '03 10:13:12AM

...this was never meant to be a shell script, and I don't want to use xterm and X11. I want to use iTerm in conjuction with OnMyCommand, a remarkable little freeware contextual menu utility that is one of the best things about OS X. Even though I use the terminal extensively, OnMyCommand reduces my need to turn to the command line.

Therefore, you don't need to make a shell script; all you need to do is, first, read the hint so that you'll understand why you would do this : ) (if you don't use OnMyCommand or iTerm, this hint isn't for you); second, copy the text and paste it into a new command in OMCEdit; third, insert whatever shell command you want to run.



[ Reply to This | # ]
oh ok...
Authored by: macubergeek on Jun 14, '03 07:52:00AM

I must admit I've never used OnMyCommand before...so I'm clueless there..I'll download it from Versiontracker and give it a whirl...thanks for the redirect.



[ Reply to This | # ]
Use iTerm With OnMyCommand
Authored by: af3556 on Aug 07, '03 11:47:04AM

A minor change to respect the user's default shell and any dotfiles normally invoked via the login shell: replace

-e 'exec command "/bin/tcsh"'

with

-e 'exec command "sh -c \"/usr/bin/login -fp $USER\""'

or just

-e 'exec command "/usr/bin/login -fp username"'



[ Reply to This | # ]
Use iTerm With OnMyCommand - can't reliably mix AS and OMC
Authored by: af3556 on Aug 07, '03 12:07:47PM

> You can also use any of OnMyCommand's objects
> (cd __OBJ_PATH__; ls -la, for instance).

Note that AS's quoting is incompatible with OMC's / the shell's, specifically AS only accepts \\, \", \r, and \t; it will fail with any other escaped character. Which means if __OBJ_PATH__ is say "a file with spaces", the script will fail when OMC's escaping is turned on as OMC will escape the spaces ("\ ") and AS will barf.

BTW, there is a security issue if users try and avoid the incompatible quoting by turning off OMC's escape mechanism. (i.e. none, as suggested in the OMC v2.5.3 docs) - no amount of quoting on the command line can protect you from all input, as OMC does a text substitution before passing to the shell. i.e.

osascript ... -e 'write text "cd __OBJ_PATH__"' ...

if the folder name is "nasty `rm -rf ..`" then you're in trouble...



[ Reply to This | # ]
Use iTerm With OnMyCommand
Authored by: SimonDorfman.com on Nov 21, '04 08:05:10AM
AppleScript is natively supported in OMC 1.6: you do not have to use call osascript to execute AppleScript code. Here's what I added to my com.abracode.OnMyCommandCMPrefs.plist file to get this working. Also note that the code below works even when the path has spaces in it. I fixed that problem by adding single quotes around the whole '__OBJ_PATH__' enjoy

		<dict>
			<key>ACTIVATION_MODE</key>
			<string>act_folder</string>
			<key>COMMAND</key>
			<array>
				<string>
				tell application "iTerm"
					activate
					set myterm to (make new terminal)
					tell myterm
						set mysession to (make new session at the end of sessions)
						tell mysession
							exec command "/bin/tcsh"
							write text "cd '</string><string>__OBJ_PATH__</string><string>'; ls -alF"
						end tell
					end tell
				end tell
				</string>
			</array>
			<key>ESCAPE_SPECIAL_CHARS</key>
			<string>esc_for_applescript</string>
			<key>EXECUTION_MODE</key>
			<string>exe_applescript</string>
			<key>NAME</key>
			<string>Change dir to this folder and list content in iTerm</string>
			<key>NOTES</key>
			<string>Does not work with folders containing non-ASCII chars</string>
			<key>VERSION</key>
			<integer>1</integer>
		</dict>


[ Reply to This | # ]