Do you hate coming to the office, firing up your favourite text editor, getting ready to do some work, and .. you forgot to start your Vagrant machine? Now you have to open up the terminal, type vagrant up, wait 90+ seconds for the beast to load and .. it doesn’t work because you forgot to connect to the VPN and Puppet cannot correctly provision the box without it. So, you do that too.

Now that everything is setup – you code the entire day, pack your things, arrive home, start browsing threads on Hacker News and… the low battery warning comes up because you forgot to close Vagrant.

There are just too many irrelevant little tasks we need to keep in our brain cache, and there is precious little space in there for useless, repetitive information. Whatever you work with, all of us have these little tasks we do day in and day out that only waste time and demand energy.

For those of you on OSX, there is something that can help. I made some tiny little AppleScripts that solves these annoying problems.

automation

The “before work” script contains two parts. One for opening a list of apps found in apps.txt, and another one for running your custom scripts.

[applescript]set current_path to POSIX path of ((path to me as text) & "::")
— get work apps
set appList to {}
set myApps to paragraphs of (read current_path & "apps.txt")
repeat with nextLine in myApps
if length of nextLine is greater than 0 then
copy (nextLine as string) to the end of appList
end if
end repeat

— open work apps
repeat with i in appList
tell application i to activate
end repeat

— run other scripts from folder
set scriptList to {"connect_tunnelblick", "open_vagrant", "open_chrome_tabs"}
repeat with i in scriptList
run script current_path & i & ".applescript"
end repeat[/applescript]

The open_vagrant script just opens an iTerm session and runs a vagrant up command:

[applescript]set open_vagrant to "z puppet; vagrant up;"

tell application "iTerm"
activate
try
set mysession to current session of current terminal
on error
set myterm to (make new terminal)
tell myterm
launch session "Default"
set mysession to current session
end tell
end try

tell mysession
write text open_vagrant
end tell
end tell[/applescript]

AppleScript is a pretty funny language to code in, and it’s still rough around the edges. For example to close iTerm you first have to ignore the system events, then issue the exit for the app, catch system events, and finally press enter.

[applescript]set close_vagrant to "z puppet; vagrant halt -f;"

— close vagrant
tell application "iTerm"
activate
set myterm to (make new terminal)
tell myterm
launch session "Default"
set mysession to current session
end tell

tell mysession
write text close_vagrant
end tell

delay 5
end tell

— quit iTerm
ignoring application responses
tell application "iTerm"
quit
end tell
end ignoring

delay 2
tell application "System Events" to keystroke return[/applescript]

Is it worth the time? XKCD has the answer:

is_it_worth_the_time

Given that I do these things daily, I may save between 1 and 5 minutes per day – which becomes 1-6 days over 5 years. It doesn’t sound like much, but given that time is highly, uniquely and equitably limited, we should strive to do our best in squashing annoying things that chop it.

Alternative: got a tip on Facebook about Tmuxinator, which automates opening programs in your terminal. Also, put the scripts somewhere searchable by Spotlight so you can launch them easily, or use my Alfred workflow.

About the author: I love reading, writing and spreading valuable stories. You should follow me on TwitterFacebook and Google+. Check out other cool projects I made on Github.


uberVU is part of the Hootsuite team. Read more about it here