Posts Tagged ‘terminal’

Command Tab or Dock stops working on Mac OS x

Wednesday, October 6th, 2010

I was completely useless the other day when Command Tab (or Apple Tab) stopped working. Also my dock wouldn’t show up. I was able to regain these features by opening Terminal.app and issuing:


killall Dock

Apparently Dock also controls the Command Tab feature.

Blue tint on mac wake from sleep

Sunday, September 5th, 2010

If you wake your mac from sleep and suddenly your screen is all a slightly blueish hue. Open up Terminal.app and issue this command:


/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/Resources/DMProxy

Update: This also works if you screen gets a funny bluish tint when Powerpoint slideshow mode goes back and forth from fullscreen.

terminal slow on snow leopard

Saturday, July 3rd, 2010

On my Mac os X 10.6 machine at work I’ve suffered from slow scroll speed using vim with syntax highlighting in Terminal.app. The screen refreshes very slowly when using colored syntax highlighting in vim and only in Terminal.app (xterm is fine, but I don’t like to have to start x11 and all just for a terminal, and anyway Terminal.app is fine otherwise).

Apparently something got broken during Terminal.app version 2.0.2 and Terminal.app version 2.1, the latter even being 64-bit. Who knows what it was but I can find any reason to use the new Terminal so I will use the old one on the new machine.

I’m backing up my old copy of terminal, but you should probably find your own to be safe. The scroll speed works fine with the old Terminal.app. Just drag it over from an intel machine and it should work find. All my bash profiles and vimrc loaded just fine, so I didn’t need to set anything else up.

Change screenshot file format in Snow Leopard to PNG

Wednesday, June 16th, 2010

Just started working on a snow leopard machine and have been annoyed that the screenshots are saved as PDFs. To switch back to png I opened Terminal.app and issued this command:


defaults write com.apple.screencapture type png

Then you must issue:


killall SystemUIServer

to make the change take effect.

Note: You can replace png in the above with any of these: png, pdf, tiff, pict, bmp, gif, psd, sci, or tga.

source

Open terminal here (parent directory of drag-and-dropped file), applescript

Monday, April 12th, 2010

Here’s a little script I’ve been meaning to write for while. Often I’m roaming around in the Finder GUI and I want to switch to a terminal. This is not so hard if I already have a terminal window open I can type cd into the command line then drag the current folder I’m looking at in Finder onto the terminal window and I get the full absolute path to that file. Then I hit enter to navigate there on the command line.

To make this totally effortless and seemless if Terminal.app is not already running. I wrote the following applescript:


-- if not given files then just act like opening a terminal to the home screen. I.e. `cd`
tell application "Terminal"
  activate
  do script ""
end tell

-- if fiels are drag-and-dropped on this app
on open (these_files)
  -- just use first file if more than one
  set this_path to (quoted form of basedir(POSIX path of (first item of these_files)))
  tell application "Terminal"
    activate
    do script "cd " & this_path
  end tell
end open

on basedir(the_path)
  set last_occurrence to last_offset(the_path, "/")
  if last_occurrence is equal to 0 then
    return "."
  end if
  if last_occurrence is equal to 1 then
    return "/"
  end if
  return items 1 thru (last_occurrence) of the_path as string
end basedir

on last_offset(the_text, char)
  try
    set len to count of the_text
    set reversed to reverse of characters of the_text as string
    set last_occurrence to len - (offset of char in reversed) + 1
    if last_occurrence > len then
      return 0
    end if
  on error
    return 0
  end try
  return last_occurrence
end last_offset

Using some older functions I wrote:
last offset of a character in a string
base directory of a POSIX path

Then I save as an application and drag a shortcut onto my finder bar.

Bash keyboard shortcuts on Mac OS X

Sunday, March 14th, 2010

Found this list of Bash keyboard shortcuts on Mac OS X. Here are my favorites that I want to remember:

Say you have typed ( where the pipe, “|”, represents where your cursor is):


mv foo bar|

Then if you hit CTRL+[ then B you will move back one word:


mv foo |bar

To go forward again hit CTRL+[ then F:


mv foo bar|

Now the coolest one, to swap the last two words hit CTRL+[ then T:


mv bar foo|

Find and delete all .DS_Store files recursively

Friday, November 6th, 2009

This is posted all over the web, but sanity’s sake I’ll post it again here. This use of the unix command line program find will locate and remove all the .DS_Store files that Finder populates throughout your directories. The following removes all files by the name .DS_Store in the current directory recursively:


find . "-name" ".DS_Store" -exec rm {} \;

“See” shell scripts in action with applescript

Sunday, September 13th, 2009

Here’s a simple script to open Terminal.app and execute a shell script.


tell application "Terminal"
	activate
	do script "ls"
end tell

Note: Note the subtle difference from another applescript feature you might be used to, namely do shell script. The latter, do shell script, when executed anywhere in an applescript runs a script at root level (but without root permissions). So running a script like:


set contents to do shell script "ls"

The variable contents will hold the return of ls for the root directory, /. On the other had something like the code at the top will execute ls at the default location of a new Terminal window, which (unless you have changed it) is by default the home directory of the current user. So in a Terminal tell block,

do script "ls"

opens a new terminal window and executes ls in that window, presumably at the user’s home directory, ~.

Make delete key in Vi and Vim in Mac OS X 10.5 send backwards delete (backspace) instead of forward delete

Monday, September 7th, 2009

I recently upgraded to Mac OS X 10.5 and reinstalled vim (VIM – Vi IMproved 7.2). I noticed that the delete key on my keyboard was forward deleting (deleting the next character to the right of the cursor) rather than backward deleting (deleting the previous character to the right of the cursor). It felt like the backspace and delete (windows-style) keys had been switched or swapped.

Advanced settings in Terminal.app

I fixed the problem by changing my Terminal.app settings. Under Terminal > Preferences choose Advanced. Check “Delete sends Ctrl-H”. Now, vi and vim should understand the delete key more intuitively.

Note: Mapping the “delete” key in my vimrc file seemed like probably the correct way to do this, but that’s a lot of trouble. Is there any reason not to do it this way?

Remove icon from file/folder on Mac OS X

Monday, July 27th, 2009

I was messing with the icon of my external drive and managed to lose the ability to change or reset the icon using “Get info” in the GUI. I found a way to forcibly remove the icon, and in doing this found a nice way to change icons outside the GUI.

To remove a file’s icon or in this case my volume’s icon:
in a Terminal cd into that Volume, usually /Volume/[drive name]/, then remove the icon file called .VolumeIcon.icns with the command:


rm .VolumeIcon.icns

This prompted me to examine what icon files for regular files look like, for a tiff image called green.tiff the icon file was in the same folder called ._green.tiff. I wanted my volume to have the same icon as this tiff image, only the transparency wasn’t showing up correctly. It showed up correctly in the tiff file’s icon, but not when I copied the icon using “Get info” to the volume. On the command line I was able to give my volume a transparent icon from a tiff file by simply coping the icon file of the image onto the icon file of the drive:

 cp ._green.tiff .VolumeIcon.icns 

Update:
Might as well post the transparent icon images I changed my volume icons to. The idea was to have the color of the drive match the USB cord attached to the computer:

Red Drive IconGreen Drive IconBlue Drive IconPink Drive IconYellow Drive IconTeal Drive IconPurple Drive IconBlack Drive Icon


Download a folder containing all of the above read to use