forked from likes-gay/win-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ps1
209 lines (169 loc) · 7.22 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#functions
function UnPin-App { param(
[string]$appname
)
try {
((New-Object -Com Shell.Application).NameSpace("shell:::{4234d49b-0245-4df3-b780-3893943456e1}").Items() | ?{$_.Name -eq $appname}).Verbs() | ?{$_.Name.replace("&", "") -match "Unpin from taskbar"} | %{$_.DoIt()}
return "App '$appname' unpinned from Taskbar"
} catch {
Write-Error "Error Unpinning App! (Is '$appname' correct?)"
}
}
# Download user config file
try {
$configFileUrl = "https://raw.githubusercontent.com/likes-gay/win-config/main/configs/{0}.json"-f $Env:UserName
Invoke-WebRequest $configFileUrl -outfile "config.json"
} catch {
Write-Output "No config file detected, please create one in this folder: https://github.com/likes-gay/win-config/blob/main/configs/"
Exit
}
# Parse config file
try {
$configFile = Get-Content .\config.json -Raw | ConvertFrom-Json
} catch {
Write-Error "Malformed config file"
Exit
}
# Delete config file after use
Remove-Item -Path .\config.json
# Install git
if ($configFile."Install-git") {
winget install --id Git.Git -e --source winget
}
# Unpin unused apps from the taskbar
if ($configFile."Unpin-apps") {
UnPin-App "Microsoft Edge"
UnPin-App "Microsoft Store"
UnPin-App "Mail"
}
# Turns on dark mode for apps and system
if ($configFile."Dark-mode") {
$themesPersonalise = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"
Set-ItemProperty -Path $themesPersonalise -Name "AppsUseLightTheme" -Value 0 -Type Dword
Set-ItemProperty -Path $themesPersonalise -Name "SystemUsesLightTheme" -Value 0 -Type Dword
}
$explorer = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced"
# Remove task view
if ($configFile."Remove-task-view") {
Set-ItemProperty -Path $explorer -Name "ShowTaskViewButton" -Value 0
}
# Set task bar search type
if ($configFile.'Task-bar-search-mode') {
$taskBarSearchModeRegKey = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Search"
if ($configFile.'Task-bar-search-mode' -eq "Hidden"){
Set-ItemProperty -Path $taskBarSearchModeRegKey -Name "SearchboxTaskbarMode" -Value 0
}
if ($configFile.'Task-bar-search-mode' -eq "Icon"){
Set-ItemProperty -Path $taskBarSearchModeRegKey -Name "SearchboxTaskbarMode" -Value 1
}
if ($configFile.'Task-bar-search-mode' -eq "Bar"){
Set-ItemProperty -Path $taskBarSearchModeRegKey -Name "SearchboxTaskbarMode" -Value 2
}
}
# Turn on file extensions in File Explorer
if ($configFile."File-extentions") {
Set-ItemProperty -Path $explorer -Name "HideFileExt" -Value 0
}
# Hide desktop icons
if ($configFile."Remove-desktop-icons") {
Set-ItemProperty -Path $explorer -Name "HideIcons" -Value 1
}
# Enable seconds in clock
if ($configFile."Seconds-in-clock") {
Set-ItemProperty -Path $explorer -Name "ShowSecondsInSystemClock" -Value 1 -Force
}
# Enable 12 hour time in clock
if ($configFile."12-hr-clock") {
Set-ItemProperty -Path $explorer -Name "UseWin32TrayClockExperience" -Value 0 -Force
}
# Enable the clipboard history
if ($configFile."clipboard-history") {
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Clipboard" -Name "EnableClipboardHistory" -Value 1
}
# Set print screen to open snipping tool
if ($configFile."Print-scrn-snipping-tool") {
Set-ItemProperty -Path "HKCU:\Control Panel\Keyboard" -Name "PrintScreenKeyForSnippingEnabled" -Value 1 -Type Dword
}
# Set scroll lines to user defined
if ($configFile."Set-scroll-lines") {
$scrollSpeed = $configFile."Set-scroll-lines"
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class WinAPI {
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
}
"@
Set-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name "WheelScrollLines" -Value $scrollSpeed
[WinAPI]::SystemParametersInfo(0x0069, $scrollSpeed, 0, 2)
[WinAPI]::SendMessageTimeout(0xffff, 0x1a, [IntPtr]::Zero, "Environment", 2, 5000, [IntPtr]::Zero)
}
# Turn on "Live Caption" in Google Chrome
if ($configFile."Enable-live-caption-chrome") {
$originalFile = "$env:LocalAppData\Google\Chrome\User Data\Default\Preferences"
$content = Get-Content -Path $originalFile | ConvertFrom-Json
$content | Add-Member -MemberType NoteProperty -Name "accessibility" -Value @{
captions = @{
live_caption_enabled = $true
}
} -Force
$content | ConvertTo-Json -Compress | Set-Content -Path $originalFile
}
# Set default browser to Chrome
if ($configFile."Default-browser-chrome") {
Invoke-WebRequest "https://raw.githubusercontent.com/likes-gay/win-config/main/default_browser.vbs" -OutFile .\default_browser.vbs
Invoke-Expression "Cscript.exe .\default_browser.vbs //nologo"
Remove-Item -Path ".\default_browser.vbs"
# Setup edge redirect - https://github.com/rcmaehl/MSEdgeRedirect/wiki/Deploying-MSEdgeRedirect
if ($configFile."Setup-edge-redirect") {
Invoke-WebRequest "https://github.com/rcmaehl/MSEdgeRedirect/releases/latest/download/MSEdgeRedirect.exe" -OutFile .\MSEdgeRedirect.exe
Invoke-WebRequest "https://raw.githubusercontent.com/likes-gay/win-config/main/edge_redirect.ini" -OutFile .\edge_redirect.ini
Start-Process "MSEdgeRedirect.exe" -ArgumentList "/silentinstall",".\edge_redirect.ini" -PassThru
Remove-Item -Path ".\edge_redirect.ini"
Remove-Item -Path ".\MSEdgeRedirect.exe"
}
}
if ($configFile."Close-edge"){
try {
Stop-Process -Name msedge -Force
} catch {
Write-Output "Microsoft Edge is already shut"
}
}
# Open useful tabs
if ($configFile."Open-tabs") {
for (
$i = 0
$i -lt $configFile."Open-tabs".Count
$i++
){
Start-Process $configFile."Open-tabs"[$i]
}
}
# Set accent colour from config file
if($configFile.'Accent-colour'){
$ColorValue = $configFile.'Accent-colour'.Split(' ') | ForEach-Object { "0x$_" }
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Accent" -Name "AccentPalette" -Value ([byte[]]$ColorValue)
}
Stop-Process -processName: Explorer # Restart explorer to apply changes that require it
# Easter egg ;)
if ($configFile.'Funny-joe-biden'){
$images = (Invoke-WebRequest "https://raw.githubusercontent.com/likes-gay/win-config/main/photos.txt").Content.Split([Environment]::NewLine)
# Create folder to store downloaded images in to prevent clutter.
$downloadPath = $env:USERPROFILE + "\Downloads\likes-gay-images"
If (!(test-path $downloadPath)) {
New-Item -ItemType Directory -Path $downloadPath
}
foreach ($i in $images) {
# Get the name of the image from the URL
# Windows will not open images in the photo viewer unless they have a file extension.
$imageName = $i.split("/")[$i.split("/").Count - 1]
# Download and open the image
Invoke-WebRequest -Uri $i -OutFile $downloadPath\$imageName
Start-Process $downloadPath\$imageName
}
}
Exit