Skip to content

Instantly share code, notes, and snippets.

@mikker
Created March 5, 2013 16:12
Show Gist options
  • Save mikker/5091433 to your computer and use it in GitHub Desktop.
Save mikker/5091433 to your computer and use it in GitHub Desktop.
Something I use everyday.
#!/usr/bin/env ruby
# In the morning:
# $ firmafon
# In the afternoon
# $ firmafon -q
apps = %w{BreakTime Fogbugz HipChat FirmafonApps}
def bracketize(str = "")
str.gsub(/^([A-Z])/, '["\1"]')
end
def run(app)
puts "Running #{app}"
`open -g -a '#{app}'`
end
def quit(app)
running = `ps -A | grep "#{bracketize app}"`.length > 0
if running
puts "Quitting #{app}"
`osascript -e 'tell application "#{app}" to quit'`
end
end
def mysql_running?
running = File.exist?("/usr/local/var/mysql/#{`hostname`.strip}.pid")
end
def start_mysql
puts "Starting MySQL server"
`mysql.server start` unless mysql_running?
end
def stop_mysql
puts "Stopping MySQL server"
`mysql.server stop` if mysql_running?
end
def unmount_sidekick
puts "Unmounting disk"
`if [ -d /Volumes/Sidekick ]; then diskutil unmountDisk /Volumes/Sidekick; fi`
end
if ARGV.include?("-q")
apps.each { |app| quit app }
# stop_mysql
unmount_sidekick
else
apps.each { |app| run app }
# start_mysql
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment