Tag Archives: mac

Quit Terminal.app after closing last window

I use Terminal.app on a daily basis, mostly for my research as I am currently building an adjoint of the CMAQ model.  I like to have 4+ windows open at all times while working in Terminal, as it allows me to watch the progress of a simulation while also editing files, compiling, etc.  I have macros setup that will log me into and out of each terminal window.  One of the frustrating things that I ran into was that, after the macro logged me out of the final window, I wanted the Terminal application to quit.  Now, I very easily could have added the Quit Application command to the macro, however I was hoping for a solution that would also work even if the macro wasn’t called.  I surfed the web for a while and found nothing, until I got a response on my post on Apple’s forums.

I am copying te response to this website, however all credit for the material goes to François J. Perreault, who answered the question.

Here’s how to have Terminal quit automatically after closing all your shells:

  1. Create a new text file in your home folder named “autoQuitTerminal.scpt“:
    tell application "Terminal"
     
      --If there is only one tab remaining, and it contains 
      --the word "logout" then this is the final window
      if (count of (tabs of (every window whose visible is true))) = 1 then
           try
                set theContents to words of ((contents of tab 1 of window 1) as Unicode text)
                set exitLastTab to (theContents contains "logout")
           on error
                set exitLastTab to false
           end try
     
           if exitLastTab is true then
                quit
           end if
     
       else if (count of (tabs of (every window whose visible is true))) < 1 then
      --If no window remains open, then obviously we can quit the app.
      --This would occur when the final window is closed without ‘exit’
            quit
       end if
     
    end tell

    Continue reading Quit Terminal.app after closing last window

Mac OS X Quit Application from Command Line

When doing any type of programming or scripting, I do my best to streamline everything (see this post and this post).  Basically anything I do in the Terminal that can be automated, I try to automate.  In addition to the posts linked above, I also have macros set up to login me into the supercomputer that I do most of my research on.

When I first open Terminal, I have it set to open 4 Terminal windows in specified locations.  For those of you who don’t know how to do this, I will soon be providing a post detailing the necessary steps to accomplish this.

Continue reading Mac OS X Quit Application from Command Line

How to: Passwordless SSH

As some of you know, I prefer to set up passwordless logins to all of my accounts on remote machines. I recently made a post describing how to enable passwordless SSH to compute nodes, however what if you are attempting to enable passwordless logins to remote machines?

If you are on a Linux machine, or have a copy of the “ssh-copy-id” script on your system then the process is fairly simple.  You must first create the private/public key pairing.  For passwordless SSH, just accept the defaults for each option.

ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cmaqadj/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/cmaqadj/.ssh/id_rsa.
Your public key has been saved in /home/cmaqadj/.ssh/id_rsa.pub.

Continue reading How to: Passwordless SSH

/etc/motd Formatting

It is good practice to announce server maintenance dates and scheduled downtime dates many days prior to the actual downtime. The easiest way to ensure that all users become aware of the scheduled downtime is to place an alert in /etc/motd.

For those of you that don’t know, /etc/motd is the file that gets printed to the screen when a user first logs into the system.

However, in the case of our server (possibly most servers), users tend to ignore the contents of motd since it very rarely changes. In order to attract the attention of any user that logs into the system, I have begun adding formatting (bold, underline, colors, etc) to the motd file on our server.

Formatting can be easily added to any motd using ANSI codes. For example, below is a copy of a sample maintenance announcement for our server:


Notice that the text “Server Maintenance” is what first got your attention. This is because of the different color, bold text, and blinking text (blinking text is not supported in IE, Chrome, and Safari).


Below is a list of some of the formatting commands i use, as well as the corresponding displayed text. Note that the ^[ that appears often in purple in the below images is the escape character. To insert this character, within VIM press and hold ctrl + ‘v’ and then press escape.

Command

 

Output

 

 

Enhanced by Zemanta

Using the Debugging Tool Valgrind

Valgrind is an excellent, and sometimes necessary, tool for debugging troublesome programs. According to Valgrind’s website, the program can “automatically detect many memory management and threading bugs, avoiding hours of frustrating bug-hunting, making your programs more stable. You can also perform detailed profiling to help speed up your programs”.

Valgrind contains a variety of tools for use while debugging. The program can be used to debug a wide variety of programming languages including, but not limited to, C, C++, Java, Perl, Python, Fortran, Ada, etc. Using these tools, you can:

  • Detect memory errors (using the tool Memcheck)
  • Make programs run faster (using the cache and branch-prediction profilerCachegrind)
  • Detect thread errors (using the tool Helgrind and/or DRD)
  • Profile heap usage (using the tool Massif and/or DHAT)

Continue reading Using the Debugging Tool Valgrind