Jump to content
vitor

Extra tab is open when using iTerm2

Recommended Posts

Alfred v2.0.1 (173) | OSX 10.8.3

 

If iTerm2 is chosen as the Terminal to use, commands passed through Alfred will, if iTerm2 is not open, cause it to launch with two tabs, executing the commands on the second tab. This happens whether the command is run via the Terminal / Shell feature, or via a Workflow. It becomes annoying because most of the times I use this feature, I want the command to run and the terminal to close, which does not happen since the other tab stays open.

 

I’m using the code in http://www.alfredforum.com/topic/721-executing-iterm2-terminal-commands-in-current-shell/?hl=iterm to go around this issue in the meantime, has it (so far) seems to avoid the issue.

Share this post


Link to post

Alfred v2.0.1 (173) | OSX 10.8.3

 

If iTerm2 is chosen as the Terminal to use, commands passed through Alfred will, if iTerm2 is not open, cause it to launch with two tabs, executing the commands on the second tab. This happens whether the command is run via the Terminal / Shell feature, or via a Workflow. It becomes annoying because most of the times I use this feature, I want the command to run and the terminal to close, which does not happen since the other tab stays open.

 

I’m using the code in http://www.alfredforum.com/topic/721-executing-iterm2-terminal-commands-in-current-shell/?hl=iterm to go around this issue in the meantime, has it (so far) seems to avoid the issue.

 

This is an issue with iTerm2 which I've been talking with George about for quite some time. When using the AppleScript to prevent this, there is a long pause of up to 5 or 6 seconds caused by iTerm2. Hopefully he can resolve this fully one day :)

Share this post


Link to post

There seems, however, to be something weird about the way Alfred calls iTerm2 (or how it executes Applescript, perhaps).

 

Consider this script

set command to "echo testing"

tell application "System Events"
	set _wasRunning to exists (processes where name is "iTerm")
end tell

tell application "iTerm"
	activate
	
	if not _wasRunning then
		set _session to current session of current terminal
	else
		set _term to (make new terminal)
		tell _term
			launch session "Default"
			set _session to current session
		end tell
	end if
	
	tell _session
		write text command
	end tell
end tell

When I run this via the Applescript Editor, it works as intended (if iTerm2 isn’t running, it opens a single window and executes the command; if iTerm2 is already running, it creates a new window and runs the command there).

 

However, when I try this with the “on alfred_script(q)” handler wrapping it, the problem arises (it works the same if iTerm2 is already running, but if it isn’t it creates two windows, and runs the command on the second one). What is it about the way Alfred executes the code that makes it behave that way? Keep in mind that I’m not the biggest fan of Applescript and usually avoid it where I can, so there could certainly be something I’m missing here, but the fact that it works in Applescript Editor and not in Alfred is strange.

Edited by vitor

Share this post


Link to post

Hm this is quite an interesting and different way to how George suggested the AppleScript should be done - I'm going to have a bit of a look into this!

 

Cheers,

Andrew

Share this post


Link to post

I'd like to point out that I am having a similar problem with an applescript (triggered via automator) which launches iterm2. Here's the script:

 

on run {input, parameters}
    tell application "Finder"
        set dir_path to "\"" & (POSIX path of (input as string)) & "\""
            -- display dialog dir_path
    end tell
    CD_to(dir_path)
end run

on CD_to(theDir)
    tell application "iTerm"
        activate
        try
            set t to the last terminal
        on error
            set t to (make new terminal)
        end try
        tell t
            launch session "Default Session"
            tell the last session
                write text "cd " & theDir & ";clear;ls"
            end tell
        end tell
    end tell
end CD_to

 

 

Taken from http://peterdowns.com/posts/open-iterm-finder-service.html

 

As much as I am hoping for a solution, the problem does look like it is with iTerm

Share this post


Link to post

Folks,

I've been hearing good things about iTerm2 again lately, but over two years since first reporting this issue it still exists in the latest version of OSX / iTerm2 / Alfred.

I'm extremely reluctant to move to iTerm2 because of this issue alone.

Does nobody else care?

Johnny.

Share this post


Link to post
×
×
  • Create New...