A pleasant walk through computing

Home

Comment for me? Send an email. I might even update the post!

Tid Bits: VS Code: Orange Icon Resurrection

   

Update 2018-08-19: I improved the script to manage the entire icon replacement, and am handling the recent change to VS Code using a user-profile-based install.

Update 2018-09-08: The script now prompts for whether to create the desktop icon. In most cases, after the first run, you won't need to. It also refreshes the icon cache, so you should see the change immediately.

I never understood why so many developers--people who generally have no visual design sense--decided that the orange Visual Studio Code icon was where they would take their stand.

I liked the orange, for a few reasons:

  1. It stood out from my purple Visual Studio icon.
  2. It was bold.
  3. I don't have some childhood trauma related to orange.

On Windows, it's not practical to change the icon completely back to orange. That would require modifying the code.exe file. But you can get most of the way there. The steps below will change the icon for:

  1. Right-click folder/file > Open with VS Code
  2. Right-click pinned shortcut > Visual Studio Code
  3. Shortcut

It won't change the icon in the VS Code editor, or in context menu Right-click pinned shortcut > New Window

Here's a 7z file with the orange icons and Powershell script.

vs-code-orange.7z

Find your VS Code Image Path

As of August 2018, VS Code recommends a user setup, which writes the app to the user's profile. Before that, the app was written to Program Files. The Powershell script determines the correct location.

User Profile Path
%LOCALAPPDATA%\Programs\Microsoft VS Code\resources\app\resources\win32\

Program Files Path
%ProgramFiles%\Microsoft VS Code\resources\app\resources\win32\

Replace the VS Code icons

There are three icons in the Image Path. Backup and replace all three with the same sizes and names. For changing the .png files, Paint.Net will work. For the .ico file, I like Greenfish Icon Editor Pro.

Update the Registry

There are four registry keys that point to Code.exe for the icon. Change these to [ImagePath]]\code_file.ico.

HKEY_CLASSES_ROOT*\shell\VSCode\Icon" HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\Icon HKEY_CLASSES_ROOT\Drive\shell\VSCode\Icon HKEY_CLASSES_ROOT\Software\Classes\Directory\shell\VSCode\Icone

Use a Shortcut to Open VS Code

  1. Right-click in a folder, choose New > Shortcut
  2. Item location: "%LOCALAPPDATA%\Programs\Microsoft VS Code\code.exe" or "%ProgramFiles%\Microsoft VS Code\Code.exe"
  3. Name: "VS Code"
  4. Right-click the shortcut, click Change Icon.
  5. Select [ImagePath]\code_file.ico

You can now drag this icon into the task bar to pin it.

Powershell Script

Here's a Powershell script that does everything. Be sure the image files are in the script folder.

# This is the new "standard" path
$basePath = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\resources\app\resources\win32\"

If (-Not (Test-Path $basePath))
{
    # This is the old path
    $basePath = "$env:ProgramFiles\Microsoft VS Code\resources\app\resources\win32\"
}

Write-Output "VS Code Path: $basePath"


Write-Output "Copying orange icons"
$iconFile = Join-Path $basePath  "code_file.ico"

Copy-Item -Path @(Join-Path $PSScriptRoot *) -Include *.png,*.ico -Destination $basePath

Write-Output "Setting Registry..."
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
Set-ItemProperty -LiteralPath "HKCR:\*\shell\VSCode" -Name Icon -Value $iconFile
Set-ItemProperty -Path HKCR:\Directory\Background\shell\VSCode -Name Icon -Value $iconFile
Set-ItemProperty -Path HKCR:\Drive\shell\VSCode -Name Icon -Value $iconFile
Set-ItemProperty -Path HKCU:\Software\Classes\Directory\shell\VSCode -Name Icon -Value $iconFile
Remove-PSDrive -Name HKCR 

$shortcut = Read-Host "Create a shortcut?"
if ($shortcut -eq 'y')
{
    Write-Output "Creating shortcut in Desktop"
    $TargetFile = $basePath + "..\..\..\..\code.exe"
    $ShortcutFile = "$env:UserProfile\Desktop\VS Code.lnk"
    $WScriptShell = New-Object -ComObject WScript.Shell
    $Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
    $Shortcut.TargetPath = $TargetFile
    $Shortcut.IconLocation = $iconFile
    $Shortcut.Save()
}

# refresh icon cache
Update-ExplorerIcon

Write-Output "Finished."
Pause




# http://community.idera.com/powershell/powertips/b/tips/posts/refreshing-icon-cache
function Update-ExplorerIcon {
  [CmdletBinding()]
  param()

  $code = @'
private static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff); 
private const int WM_SETTINGCHANGE = 0x1a; 
private const int SMTO_ABORTIFHUNG = 0x0002; 
 

[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
 static extern bool SendNotifyMessage(IntPtr hWnd, uint Msg, UIntPtr wParam,
   IntPtr lParam);

[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] 
  private static extern IntPtr SendMessageTimeout ( IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult ); 
 
 
[System.Runtime.InteropServices.DllImport("Shell32.dll")] 
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);


public static void Refresh()  {
    SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero);
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, IntPtr.Zero, null, SMTO_ABORTIFHUNG, 100, IntPtr.Zero); 
}
'@

  Add-Type -MemberDefinition $code -Namespace MyWinAPI -Name Explorer 
  [MyWinAPI.Explorer]::Refresh()

}

Tid Bits: Use Visual Studio for Git Diff/Merge

The instructions below are for Visual Studio 2017 Community Edition. Substitute Professional or Enterprise as needed.

[difftool "vstudio"]
  cmd = 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsDiffMerge.exe' $LOCAL $REMOTE Source Target //t
[mergetool "vstudio"]
  cmd = 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/TeamFoundation/Team Explorer/vsDiffMerge.exe' $LOCAL $REMOTE $BASE $MERGED //m
  trustedExitCode = true


# To use as default
[diff]
	tool = vstudio
[merge]
	tool = vstudio
	conflictstyle = diff3
[mergetool]
	keepBackup = false

Command line use:

git mergetool
git difftool

git mergetool --tool=vstudio
git difftool --tool-vstudio

Variables, prefixed with $, are specifying file paths. Note they are enclosed in quote marks, so that spaces in file paths won’t break the command. Source and Target are just labels Visual Studio will use for the files . The /t flag will open the diff in a temporary tab instead of a persisted tab. The /mflag denotes it is a merge in contrast to diff.

3 Chrome Extensions for Performance, Research, and Blogging

Efficiency Rag 1

I like to be efficient in my work. But I don't like to use technology when I don't have to. I've found too much technology reduces productivity. So, I might try out a whole bunch of utilities to make my life better, then settle on just a few of them.

These three Chrome extensions are useful, simple and don't use much memory.

OneTab

I often find myself with twenty or thirty tabs open when I'm trying to solve a programming problem or learn a software tool (or buy new flashlight). Just as often, I want to temporarily save those tabs and look them up later. I previously used Chrome's right-click > bookmark all tabs feature. That worked, but OneTab is much better.

OneTab will collapse all open tabs (except pinned) to a single tab containing links that can be ordered. A set of tabs can be named. Clicking on a link restores the tab and removes the link. Ctrl-click restores and keeps the link. This makes it easy to research a subject, keep a set of tabs around for a week or so, then dump them.

Added huge benefit? Collapsing to a single tab reduces memory consumption tremendously.

The Great Suspender

Even when I'm not researching, I'll have a dozen tabs open. But I won't be using them all. The Great Suspender suspends tabs after a period of time, reducing memory usage. Open the tab, choose Click to Reload, and it comes back up.

I love a simple tool that keeps my computer running at its peak.

Create Link

Create Link has made my tech writing, email and--especially--blogging life not just simpler but more enjoyable. In the past, to create a Markdown link of a web page, I'd type or copy/paste the title, then copy the URL, then select the text in my editor and create the link.

With Create Link, I press CTRL-M (a configurable shortcut key), and a Markdown link is created in my clipboard. I paste it to my editor, and I might have to edit the title text. I love this!

The utility also lets you create a link in HTML, plain text and MediaWiki.

(By the way...SVG does not suck)