Page 1 of 1

"RUN TERMINAL COMMAND" Opens two windows

Posted: Fri May 25, 2012 3:50 am
by sabdal
When I "RUN TERMINAL COMMAND" from launch bar, there are TWO terminal windows opened every time. I assume that one is the default window of Terminal and the other is one opened by launch bar..anyway to get that to stop? Also, can I get the window to close and terminal to quit after the command is run? Thanks!

Re: "RUN TERMINAL COMMAND" Opens two windows

Posted: Sun Jul 01, 2012 10:50 am
by iRounak
When I "RUN TERMINAL COMMAND" from launch bar, there are TWO terminal windows opened every time. I assume that one is the default window of Terminal and the other is one opened by launch bar..anyway to get that to stop?


Save the script below as "Terminal Command - Single Window".
To use it, bring up the script in LaunchBar.
Press space key
Enter your terminal command.
Press return key

Code: Select all

on handle_string(s)
   set commandString to s
   tell application "Terminal" -- Get a free window to run the commandString,
      activate -- (being sure to avoid creating a new session unnecessarily,
      -- while also handling the possibility that frontmost window is busy):
      set windowCount to (count of the windows)
      if windowCount is greater than 0 then
         repeat with w from 1 to windowCount
            if window 1 is busy then
               set frontmost of window 1 to false
            else
               do script commandString in window 1
               set frontmost of window 1 to true
               return
            end if
         end repeat
      end if
      tell window 1
         do script commandString
         set frontmost to true
      end tell
   end tell
end handle_string


Also, can I get the window to close and terminal to quit after the command is run?

I guess, you should not open it if you don't want to close it.
Save the script below as "Run Terminal Commands via Applescript".
Usage: same as above

Code: Select all

on handle_string(s)
   do shell script s
   set theresult to the result
   display dialog theresult
end handle_string

Re: "RUN TERMINAL COMMAND" Opens two windows

Posted: Mon Jul 02, 2012 4:16 pm
by sabdal
iRounak: thanks. First one works great but I don't understand the usage of the second script?

I also don't understand what you mean by, "I guess, you should not open it if you don't want to close it." ?

Re: "RUN TERMINAL COMMAND" Opens two windows

Posted: Mon Jul 02, 2012 8:13 pm
by iRounak
I mean if you only want to execute a command, then you should not require the terminal window. You can merely execute the command.
Save the second script as "Run Terminal Commands via Applescript".
To use it, bring up the script in LaunchBar.
Press space key
Enter your terminal command.
Press return key

You should not see any windows and still have your task done.

Re: "RUN TERMINAL COMMAND" Opens two windows

Posted: Wed Oct 22, 2014 5:24 pm
by iota
Just wanted to say "thanks" iRounak! This is still working well with OS X 10.10 Yosemite and LaunchBar 6.1.3.