Autohotkey - Chrome Profiles in Alphabetical Order

Applies To:
  • MS Windows 10 Pro v10.0.18362 Build 18362 (64-bit)
  • Google Chrome Browser v79.0.3945.88 (Official Build) (64-bit)
  • AutoHotkey v1.1.30.01
What?
This is an article to create a standalone application which lists all the Google Chrome Profiles on your Windows 10 workstation in alphabetical order.

Why?
This program will be redundant if Google ever update their Chrome browser to list the multiple profiles in alphabetical order like it used to be... but to date they have not. So I made a program that lists the profiles in alphabetical order and can be double-clicked to open the Chrome browser with that profile.

How?
So you will need to be able to run AutoHotkey or create executables from an AHK file. Here is the code that creates a GUI with a ListView with rows that can be double-clicked to open the profile. As an overview:
  1. Setup a standard AutoHotkey GUI
  2. Loop through Google Chrome Profile folders named "Profile 1", "Profile 2", etc.
  3. Scan the preferences file for JSON key "name" and extract value.
  4. Hide the first column in the list view (contains "Profile 1", "Profile 2", ...)
  5. Sort the second column (contains "Joes Personal Profile", "Joes Work Profile", etc)
  6. Create subroutine for when listview row is double-clicked to open Chrome Browser with selected Profile.
copyraw
#NoEnv  
#Warn  
SendMode Input  
SetWorkingDir %A_ScriptDir%  
#SingleInstance force

; --------------------------------------------------------------------------------------
; Set program Defaults
; --------------------------------------------------------------------------------------

Title   := "Joes Chrome Profile Opener"
Desc    := "This program will list all the Google Chrome profiles available from your login."
Version := "1.0"
Width   := 400
Height  := 800
BgColor := "FFFFFF"
MarginX := 2
MarginY := 2
Options := "+Caption +Border +OwnDialogs"
TempDir := "C:\Windows\Temp"

; --------------------------------------------------------------------------------------
; Create GUI

Gui, New, %Options%, %Title% v%Version%
Gui, Font, s12, Verdana
Gui, Color, %BgColor%
Gui, Margin, %MarginX%, %MarginY%
Gui, Add, ListView, w396 h775 gOpenProfile -Hdr +Grid, Profile|Client
ProfilePath := "C:\Users\" A_UserName "\AppData\Local\Google\Chrome\User Data\Profile*"
Loop, Files, %ProfilePath%, D
{
    FullPathArray := StrSplit(A_LoopFileLongPath, "\")
    ThisFolder := FullPathArray[9]
    PreferenceFile := A_LoopFileLongPath "\Preferences"  ; Get the preferences file from the profile
    FileRead, OutputContent, %PreferenceFile%
    NameStart := InStr(OutputContent, """name"":""")+8
    NameEnd := InStr(OutputContent, """", false, NameStart+1)
    NameLength := NameEnd - NameStart
    ClientName := SubStr(OutputContent, NameStart, NameLength)
    LV_Add("", ThisFolder, ClientName, A_LoopFileLongPath)
}
LV_Modifycol()
LV_Modifycol(1, 0)  ; hide the first column
LV_ModifyCol(2, "Sort")  ; sort the second column (profile names)
Gui, Font, s8, Verdana
Gui, Add, StatusBar,, Ready.
Gui, Show, w%Width% h%Height% x10 y10
Return

; --------------------------------------------------------------------------------------
; Subroutine: OpenProfile

OpenProfile:
    if (A_GuiEvent = "DoubleClick")
    {
        LV_GetText(ThisFolder, A_EventInfo, 1)
        ThisPathToOpen := """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" --profile-directory=""" ThisFolder """"
        Run, %ThisPathToOpen%
    }
Return

; --------------------------------------------------------------------------------------
; Closing subroutine

GuiClose:
CloseMe:
ExitApp
  1.  #NoEnv 
  2.  #Warn 
  3.  SendMode Input 
  4.  SetWorkingDir %A_ScriptDir% 
  5.  #SingleInstance force 
  6.   
  7.  ; -------------------------------------------------------------------------------------- 
  8.  ; Set program Defaults 
  9.  ; -------------------------------------------------------------------------------------- 
  10.   
  11.  Title   :"Joes Chrome Profile Opener" 
  12.  Desc    :"This program will list all the Google Chrome profiles available from your login." 
  13.  Version :"1.0" 
  14.  Width   :400 
  15.  Height  :800 
  16.  BgColor :"FFFFFF" 
  17.  MarginX :2 
  18.  MarginY :2 
  19.  Options :"+Caption +Border +OwnDialogs" 
  20.  TempDir :"C:\Windows\Temp" 
  21.   
  22.  ; -------------------------------------------------------------------------------------- 
  23.  ; Create GUI 
  24.   
  25.  Gui, New, %Options%, %Title% v%Version% 
  26.  Gui, Font, s12, Verdana 
  27.  Gui, Color, %BgColor% 
  28.  Gui, Margin, %MarginX%, %MarginY% 
  29.  Gui, Add, ListView, w396 h775 gOpenProfile -Hdr +Grid, Profile|Client 
  30.  ProfilePath :"C:\Users\" A_UserName "\AppData\Local\Google\Chrome\User Data\Profile*" 
  31.  Loop, Files, %ProfilePath%, D 
  32.  { 
  33.      FullPathArray :StrSplit(A_LoopFileLongPath, "\") 
  34.      ThisFolder := FullPathArray[9] 
  35.      PreferenceFile := A_LoopFileLongPath "\Preferences"  ; Get the preferences file from the profile 
  36.      FileRead, OutputContent, %PreferenceFile% 
  37.      NameStart :InStr(OutputContent, """name"":""")+8 
  38.      NameEnd :InStr(OutputContent, """", false, NameStart+1) 
  39.      NameLength := NameEnd - NameStart 
  40.      ClientName :SubStr(OutputContent, NameStart, NameLength) 
  41.      LV_Add("", ThisFolder, ClientName, A_LoopFileLongPath) 
  42.  } 
  43.  LV_Modifycol() 
  44.  LV_Modifycol(1, 0)  ; hide the first column 
  45.  LV_ModifyCol(2, "Sort")  ; sort the second column (profile names) 
  46.  Gui, Font, s8, Verdana 
  47.  Gui, Add, StatusBar,, Ready. 
  48.  Gui, Show, w%Width% h%Height% x10 y10 
  49.  Return 
  50.   
  51.  ; -------------------------------------------------------------------------------------- 
  52.  ; Subroutine: OpenProfile 
  53.   
  54.  OpenProfile: 
  55.      if (A_GuiEvent = "DoubleClick") 
  56.      { 
  57.          LV_GetText(ThisFolder, A_EventInfo, 1) 
  58.          ThisPathToOpen :"""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"--profile-directory=""" ThisFolder """" 
  59.          Run, %ThisPathToOpen% 
  60.      } 
  61.  Return 
  62.   
  63.  ; -------------------------------------------------------------------------------------- 
  64.  ; Closing subroutine 
  65.   
  66.  GuiClose: 
  67.  CloseMe: 
  68.  ExitApp 
Category: AutoHotkey :: Article: 698

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin bc1qf6elrdxc968h0k673l2djc9wrpazhqtxw8qqp4

Ethereum:
Donate to Joel Lipman with Ethereum 0xb038962F3809b425D661EF5D22294Cf45E02FebF
© 2024 Joel Lipman .com. All Rights Reserved.