-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWindows-Notification-Sound-Modification-Script.ps1
More file actions
109 lines (96 loc) · 3.38 KB
/
Copy pathWindows-Notification-Sound-Modification-Script.ps1
File metadata and controls
109 lines (96 loc) · 3.38 KB
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
<#
Author: AkagawaTsurunaki
#>
function ReadEventLabelsFromJsonFile {
param ()
$eventLabelsJsonFilePath = '.\EventLabels.json'
if (Test-Path $eventLabelsJsonFilePath) {
return Get-Content -Path $eventLabelsJsonFilePath -Raw -Encoding UTF8 | ConvertFrom-Json
} else {
throw [System.IO.FileNotFoundException] "$eventLabelsJsonFilePath not found."
}
}
function GetAllToneFilesInfo {
param (
[string]$toneFolderPath
)
$fileHashTable = @{}
$toneFiles = Get-ChildItem -Path $toneFolderPath -Filter *.wav
foreach ($toneFile in $toneFiles) {
$toneFileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($toneFile.Name)
$toneFileAbsPath = $toneFile.FullName
$fileHashTable[$toneFileNameWithoutExtension] = $toneFileAbsPath
}
return $fileHashTable
}
function GetEventLabel {
param (
[string]$lang,
[string]$eventLabel,
$eventLabels
)
foreach ($app in $eventLabels) {
foreach ($label in $app.EventLabels) {
if ($lang -eq 'EN' -and $label.EN -eq $eventLabel) {
return @{App=$app.App; id=$label.ID}
} elseif ($lang -eq 'ZH' -and $label.ZH -eq $eventLabel) {
return @{App=$app.App; id=$label.ID}
}
}
}
}
function CreateAppEventsSchemesNamesByPackageName {
param (
[string]$tonePackageName
)
$i = 0
$path = ""
[string]$pkgId = ""
do {
if ($tonePackageName.Length -ge 5) {
$pkgId = $tonePackageName.Substring(0, 5) + $i
} else {
$pkgId = $tonePackageName + $i
}
$path = "HKCU:\AppEvents\Schemes\Names\$pkgId"
$i = $i + 1
} while (
Test-Path $path
)
$pkgId
New-Item -Path $path
New-ItemProperty -Path $path -Name "(Default)" -Value $tonePackageName -PropertyType "String"
return
}
function SetTone {
param (
[string]$registryItem,
[string]$toneFilePath
)
if (!(Test-Path $registryItem)) {
New-Item -Path $registryItem
}
Set-ItemProperty -Path $registryItem -Name "(Default)" -Value $toneFilePath
return Test-Path $registryItem
}
$eventLabels = ReadEventLabelsFromJsonFile
$toneFolderPath = Read-Host -Prompt "Please enter the path of the folder that stores notification sounds"
$tonePackageName = Split-Path $toneFolderPath -Leaf
Write-Host "Tone package" $tonePackageName "found"
$TonePackageId = CreateAppEventsSchemesNamesByPackageName -tonePackageName $tonePackageName
$TonePackageId = $TonePackageId[0]
$allToneFilesInfo = GetAllToneFilesInfo -toneFolderPath $toneFolderPath
Write-Host $allToneFilesInfo.Keys.Count "tone file(s) found"
foreach ($toneFileName in $allToneFilesInfo.Keys) {
$eventLabel = GetEventLabel -lang 'ZH' -eventLabel $toneFileName -eventLabels $eventLabels
if ($eventLabel) {
$registryItem = "HKCU:\AppEvents\Schemes\Apps\" + $eventLabel.App +"\" + $eventLabel.ID + "\" + $TonePackageId
$toneFilePath = $allToneFilesInfo[$toneFileName]
if (SetTone -registryItem $registryItem -toneFilePath $toneFilePath) {
Write-Host "Set $registryItem to $toneFilePath"
}
}
}
Write-Host "Notification sound package $tonePackageName has been registered in your system successfully"
Write-Host "Note: You need to REBOOT your computer to make effect."
Read-Host "Press any key to exit..."