Archive for the ‘osx’ Category

cmdline screenshots in OSX

Wednesday, February 18th, 2009

Geekology describes a nice osx builtin command to create screen captures: screencapture. I wanted to create a screenshot of a mouse interaction. That requires some sort of a delay after initiating the capture. The “-T” option described facilitates this. It looks like the -T option is missing in the tiger version of this utility. Of course you can use ‘sleep’ to wait a couple of seconds:

$ sleep 5;screencapture -C ~/Desktop/screenshot.png

See also my previous post on screenshots.

‘Compact’ bash prompt

Monday, July 30th, 2007

Especially when working with cakephp, the following line in your .bash_profile script might come in handy:

HOSTCOLOR="31m"
PS1="\u@\[\e[${HOSTCOLOR}\]\h\[\e[0m\]:\w\n\[\e[33m\]\!\[\e[0m\] \$ "

It will print out the current working directory on the first line and the actual bash prompt on the second line. Making it less likely that your command will wrap lines after the first few typed characters.
It changes the command prompt from:

command line long

….into:

command line 'short'

The login prompt now shows the following info:

  • username
  • hostname in red (in my bash script, it will print red for one group of servers and blue for other servers)
  • current working directory
  • command history number, ie: use !520 to execute the previous command

Open Source Mac Apps

Saturday, December 30th, 2006

Just names and links:
Adium X, Chicken of the VNC, Colloquy, Cyberduck, Chmox, Fink, Firefox, macam, Smultron, Tomato Torrent, Virtuedesktop

Until it’s posssible to mount ssh filesystems…

Saturday, December 30th, 2006

Forget about cyberduck, the real thing is made possible by Amit Singh!! Two visitors dropped comments about about the release of this project. I’ve updated the post that I made back in September.


Until then… I will use cyberduck!!!
Cyberduck is an FTP / SFTP client that let’s you browse filesystems on systems you have ssh access to. It not only lets you upload and download files, it also file edit support. After connecting to a server, select a file and right click it. Select ‘Edit with > Smultron’.
Cyberduck monitors the file that you just opened in Smultron. If you save it, it will be automatically uploaded to the server, just like you where editing a local file.

And, of course, both Cyberduck and Smultron are Free and Open Souce ;-)
Neat!!

Batch conversion of images

Friday, December 15th, 2006

For batch image conversion, file renaming, etc, I usually use these kind of one-liners:

$ for i in `ls *.bmp` ; do echo convert $i ${i%.*}.png ;done
convert screendump_01.bmp screendump_01.png
convert screendump_02.bmp screendump_02.png
convert screendump_03.bmp screendump_03.png

When you’re satisfied with the result, have it executed by the shell:

$ for i in `ls *.bmp` ; do echo convert $i ${i%.*}.png ;done | sh

Combine PDFs

Tuesday, June 27th, 2006

Try the following Gostscript one-liner:

$ gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=combined.pdf article1.pdf article2.pdf notes.pdf

Redirecting stdout & stderr notes

Sunday, June 25th, 2006

Redirect stdout to stderr:

$ echo Oops, something went wrong >&2

Redirect stderr to /dev/null:

$ ls /home /qwerty 2> /dev/null
home:joe john

To get rid off all output:

$ ls /home /qwerty >/dev/null 2>/dev/null
# or
$ ls /home /qwerty >/dev/null 2>&1

Tar over ssh

Saturday, June 24th, 2006

Just a very short note. It’s not so difficult, but I keep on forgetting the syntax. Here it is:

me@localhost$ tar cf - . | \
    ssh user@otherhost 'cd dir; tar xf -'

Alienscan

Wednesday, June 14th, 2006

Today, I wrote a little bash scripts that scans the network for computers that are not registered in DNS. Reverse DNS to be more precise. It uses nmap to do a reverse DNS lookup for each computer it pings:

$ nmap -sPR -oG - 192.168.0.*

The result is filtered for failed DNS lookups:

$ nmap -sPR -oG - 192.168.0.* | grep "()"

Since all computers are contacted their mac address is known in the ARP (Address Resolution Protocol) table:

$ /sbin/arp | grep -w 192.168.0.35 | awk '{ print $3 }'

After looking up the MAC address, a table is presented with ip addresses and their mac addresses. This is the complete script.

Using bash variables in awk

Friday, April 21st, 2006

While there seems nothing wrong with this:

sign="--"
awk '{if ($1 == $sign ) print $1 }'

..it doesn’t give the intended result. To be able to use bash variables in awk, you first need to assign the variables with the -v option:

sign="--"
awk -v sign="$sign" '{if ($1 == sign ) print $1 }'

From the awk man page:

The option -v followed by var=value is an assignment to be done before (the awk) prog is  executed;  any  number  of  -v  options  may be present.