Skip to content

Instantly share code, notes, and snippets.

@dcparker
Created March 5, 2010 15:12
Show Gist options
  • Save dcparker/322794 to your computer and use it in GitHub Desktop.
Save dcparker/322794 to your computer and use it in GitHub Desktop.
ChromeProfile switcher. Usage: `ChromeProfile Home` / `ChromeProfile Work`
#!/usr/bin/env ruby
$profiles_path = "#{ENV['HOME']}/Library/Application Support/Google/Chrome"
Dir.chdir($profiles_path)
if ARGV[0] == 'clone'
$clone = true
ARGV.shift
elsif ARGV[0] == 'list'
puts Dir['*'].select {|d| File.directory?(d) && File.exists?("#{d}/.profile_name")}.map {|d| File.read("#{d}/.profile_name").chomp}.join("\n")
exit
end
unless $profile_name = ARGV[0]
warn "usage: #{$0} profileName"
exit
end
# Get current profile name
old_profile_name = `cat Default/.profile_name`.chomp
# Make the new profile if it doesn't already exist and if it's not the current profile
if !File.directory?($profile_name) && old_profile_name != $profile_name
if $clone
`cp -r Default #{$profile_name}`
else
`mkdir #{$profile_name}`
end
`echo "#{$profile_name}" > #{$profile_name}/.profile_name`
end
# Move current profile out of Default
unless old_profile_name
old_profile_name = "Home"
`echo "Home" > Default/.profile_name`
end
`mv Default #{old_profile_name}`
# Move new profile into Default
`mv #{$profile_name} Default`
if old_profile_name == $profile_name
puts "Already on profile `#{$profile_name}'."
else
puts "Switched Chrome from #{old_profile_name} to profile `#{$profile_name}'."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment