Friday, July 29, 2011

Get links from a page with bash

Get anchor elements from a webpage can be done with

curl URL 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2


where you replace URL with your choice, just like here:
curl http://cookpad.com 2>&1 | grep -o -E 'href="([^"#]+)"' | cut -d'"' -f2

Tuesday, July 26, 2011

Switching back to the previous application with AppleScript

If you want to simulate cmd + tab with AppleScript, here it is

tell application "System Events"
tell process "finder"
activate
keystroke tab using {command down}
end tell
end tell


You can use the same thing in bash

echo 'tell application "System Events"
tell process "finder"
activate
keystroke tab using {command down}
end tell
end tell' | osascript

Thursday, July 14, 2011

Show Git Commits By Author

It is as simply as
git log --author=<PATTERN>

for example

git log --author=viktor

Tuesday, July 5, 2011

Resize and position windows with AppleScript


-- get the dimensions of the desktop, set up few variables
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell

set width to x2 - x1
set height to y2 - y1

-- positioning iTunes, make it fullscreen
tell application "iTunes"
set the bounds of the first window to {x1, y1, x2, y2}
end tell

-- positioning Safari, halfwidth on the right
tell application "Safari"
set the bounds of the first window to {x1 + width / 2, y1, x2, y2}
end tell

-- positioning iTerm
tell application "iTerm"
set the bounds of the first window to {x1, y1, x1 + 1000, y1 + 600}
end tell

There are few useful blogposts about the topic.
www.ithug.com/2007/09/applescript-moving-and-resizing-windows or
www.ithug.com/2008/12/applescript-arranging-multiple-windows/

or you can use Divvy, which is an amazing window management app.

Generating QR Codes with Google

The google chart API has this feature.
http://chart.apis.google.com/chart?cht=qr&chl="+[YOUR_TEXT]+"&chs=[XSIZE]x[YSIZE]"

For instance
http://chart.apis.google.com/chart?cht=qr&chl="Hello World"&chs=120x120"

will generate this