"RUN TERMINAL COMMAND" Opens two windows

General discussions about LaunchBar
Post Reply
sabdal
Rank 1
Rank 1
Posts: 33
Joined: Wed Jun 18, 2008 4:49 pm

"RUN TERMINAL COMMAND" Opens two windows

Post by sabdal » Fri May 25, 2012 3:50 am

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!

iRounak
Rank 4
Rank 4
Posts: 191
Joined: Fri Oct 23, 2009 7:11 pm
Contact:

Re: "RUN TERMINAL COMMAND" Opens two windows

Post by iRounak » Sun Jul 01, 2012 10:50 am

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

sabdal
Rank 1
Rank 1
Posts: 33
Joined: Wed Jun 18, 2008 4:49 pm

Re: "RUN TERMINAL COMMAND" Opens two windows

Post by sabdal » Mon Jul 02, 2012 4:16 pm

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." ?

iRounak
Rank 4
Rank 4
Posts: 191
Joined: Fri Oct 23, 2009 7:11 pm
Contact:

Re: "RUN TERMINAL COMMAND" Opens two windows

Post by iRounak » Mon Jul 02, 2012 8:13 pm

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.

iota
Posts: 5
Joined: Tue May 04, 2010 11:39 pm

Re: "RUN TERMINAL COMMAND" Opens two windows

Post by iota » Wed Oct 22, 2014 5:24 pm

Just wanted to say "thanks" iRounak! This is still working well with OS X 10.10 Yosemite and LaunchBar 6.1.3.

Post Reply