Chrome 为从终端/ shell打开默认浏览器的命令传递浏览器配置文件名称

44u64gxh  于 2023-06-19  发布在  Go
关注(0)|答案(1)|浏览(135)

我正在尝试使用az login从cli登录到azure。根据azure文档,如果未安装edge browser,它会打开一个新选项卡,要求在默认浏览器上登录。但是,我想打开一个特定的配置文件,因为我使用不同的配置文件为不同的用户帐户。
例如:如果我使用az login,它会打开默认配置文件的默认浏览器
如果我使用azAd login(假设我将azAd创建为az with profile name for default browseralias,它会打开带有传入的配置文件名称的默认浏览器

kgsdhlau

kgsdhlau1#

我设法用一种巧妙的方法做了这件事。如果有更好的方法,我会更新它。但现在,这就是我所做的

balogin() {
    # chrome profile names in the browser UI and their profile folder names are different.
    # eg: default profile in UI might be "Abc", but its profile name is Default
    # eg: another profile in UI might be "Test Account", but its profile name might be "Profile 1"
    # so identify the profile names properly at ~/Library/Application\ Support/Google/Chrome

    cd ~/work/azureAdmin # just changed to this folder as I want to run admin login command from this folder so that some directory specific environment variables will be initialized in the background
    sleep 2 # giving 2 seconds wait in case background environment variables needs to be updated
    open -n -a "Google Chrome.app" --args --profile-directory="Profile 2" # this is the profile where I always login to chrome with admin account.
    sleep 5 # waiting for the browser to be initialized  - increase the timer if you have lot of tabs open in the profile instance
    az login # finally this will open the login browser tab in the desired profile.
}

相关问题