Automate everything... even opening your dev apps
You code the whole day at work, pack your things, arrive home, start browsing threads on Hacker News and bang... you have low battery because you forgot to close Vagrant. Damn the technology stack is too big to fit my tiny brain cache. Well, for those of you on OSX, I made some tiny little AppleScripts that solve these annoying little pesky problems.
https://xkcd.com/1319/ |
The before work script contains two parts: one for opening a list of apps found in apps.txt and another other one for running your custom scripts:
set current_path to POSIX path of ((path to me as text) & "::")The open_vagrant script just opens an iTerm session and runs a vagrant up command:
-- 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
set open_vagrant to "z puppet; vagrant up;"AppleScript is a pretty funny language to code in. However neither Linux, nor Windows have a similar equivalent, making the Mac a hacker friendly environment. Unfortunately, I think it is rough on some edges: for closing iTerm, I had to first ignore the system events, then issue the exit for the app, catch system events and finally press enter.
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
set close_vagrant to "z puppet; vagrant halt -f;"Is it worth the time? XKCD has the answer:
-- 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
http://xkcd.com/1205/ |
Given that I do these things daily and I may save between 1 and 5 minutes per day, then I save between 1 and 6 days per 5 years. It doesn't look too much, but given that time is highly, uniquely and equitably limited, we should strive doing our best in squashing annoying things that chop it.
Update: 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.