Posts Tagged mac
work.sh
Posted by rad in Programming on June 10, 2010
From a cold boot, to start working on one of my Rails projects, I need to do the following:
That’s a lot of keystrokes and mouse actions. No wonder I end up playing games most of the time, because Age of Empires III takes just one click.
I can configure MySQL and PostgreSQL to run on startup, but that’s wasteful. That’ll slow down the machine’s startup time, and sometimes I use just MySQL, on other projects I use PostgreSQL, and on other projects I use neither but instead use MongoDB. And that will just take away one step in this 5-step process to get from cold bootup to work bliss.
Ideally, there’s a one-click work button, a sideproject1 button, a sideproject2 button, etc. Press the right button and the Mac will be transformed into a mode optimized for the work to be done: run the needed apps, close unneeded apps, play music from the “work playlist”, change the desktop background, etc.
I have decided to learn AppleScript to build those magic buttons. Here’s what I’ve come up with so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh
# From: http://stackoverflow.com/questions/1589114/opening-a-new-terminal-tab-in-osxsnow-leopard-with-the-opening-terminal-windows/1590818#1590818
# (See answer by i0n that says "courtesy of Dan Benjamin" http://twitter.com/danbenjamin)
# Sets up my Infinitely terminal windows
# 1. Run MongoDB
# 2. Run redis in a new terminal tab
# 3. cd to the project
# 4. Launch Evernote
# 5. Launch Firefox
# 6. Launch GitX
# 1. Run MongoDB in a new terminal
/usr/bin/osascript <<mongo
activate application "Terminal"
tell application "System Events"
keystroke "t" using {command down}
end tell
tell application "Terminal"
repeat with win in windows
try
if get frontmost of win is true then
do script "cd ~; ./mongo.sh" in (selected tab of win)
end if
end try
end repeat
end tell
mongo
# 2. Run redis in a new terminal
/usr/bin/osascript <<redis
activate application "Terminal"
tell application "System Events"
keystroke "t" using {command down}
end tell
tell application "Terminal"
repeat with win in windows
try
if get frontmost of win is true then
do script "cd ~; ./redis.sh" in (selected tab of win)
end if
end try
end repeat
end tell
redis
# 3. cd to the workers project
/usr/bin/osascript <<workers
activate application "Terminal"
tell application "System Events"
keystroke "t" using {command down}
end tell
tell application "Terminal"
repeat with win in windows
try
if get frontmost of win is true then
do script "cd ~/Documents/projects/infinitely/workers; mate ." in (selected tab of win)
end if
end try
end repeat
end tell
workers
sleep 1
# 4. Launch Evernote
open /Applications/Evernote.app
# 5. Launch Firefox
open /Applications/Firefox.app
clear
There’s still no “Open iTunes and play songs in my ‘work’ playlist” section, but I’m working on it. And here’s something to make it more interesting: AppleScripting with Ruby!
This script borrowed heavily from the ideas of the people in this Stackoverflow thread.