2024-06-06 13:01:23 +02:00
|
|
|
Script: *show-notification-motivation-quote.ps1*
|
|
|
|
========================
|
|
|
|
|
2024-08-15 09:51:46 +02:00
|
|
|
show-notification-motivation-quote.ps1
|
2024-06-06 13:01:23 +02:00
|
|
|
|
|
|
|
|
2024-08-15 09:51:46 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
```powershell
|
2024-06-06 13:01:23 +02:00
|
|
|
|
|
|
|
|
2024-08-15 09:51:46 +02:00
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
2024-06-06 13:01:23 +02:00
|
|
|
|
|
|
|
Script Content
|
|
|
|
--------------
|
|
|
|
```powershell
|
2024-08-15 09:51:46 +02:00
|
|
|
#Api key for quotes https://api.api-ninjas.com
|
2024-06-06 13:01:23 +02:00
|
|
|
$headerQuote = @{
|
|
|
|
"X-Api-Key"="FZ/rIx6RAn/W7+3S10zrHQ==gWBfP5fO0xcUiKp3"
|
2024-08-15 09:51:46 +02:00
|
|
|
}
|
2024-06-06 13:01:23 +02:00
|
|
|
#calling api and getting quoute
|
|
|
|
$quote = Invoke-WebRequest -Uri https://api.api-ninjas.com/v1/quotes?category=inspirational -Method GET -Headers $headerQuote
|
|
|
|
#parsing json response
|
|
|
|
$quoteObj = ConvertFrom-Json $([String]::new($quote.Content))
|
|
|
|
|
|
|
|
$headlineText = $quoteObj.author
|
|
|
|
$bodyText = $quoteObj.quote
|
|
|
|
#defualt windows Icon for notification icon
|
|
|
|
$logo = 'C:\Windows\System32\@WindowsHelloFaceToastIcon.png'
|
|
|
|
|
|
|
|
#get random picture of cat
|
|
|
|
$image = Invoke-WebRequest -Uri 'https://api.thecatapi.com/v1/images/search?size=small' -Method Get
|
|
|
|
#parsing json response
|
|
|
|
$jsonObj = ConvertFrom-Json $([String]::new($image.Content))
|
|
|
|
|
|
|
|
$wc = New-Object System.Net.WebClient
|
|
|
|
#put cat picture into your user pictures folder
|
|
|
|
$wc.DownloadFile($jsonObj.url, "C:\Users\" + $Env:Username + "\Pictures\test.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
$xml = @"
|
|
|
|
<toast>
|
|
|
|
<visual>
|
|
|
|
<binding template="ToastGeneric">
|
|
|
|
<text>$($headlineText)</text>
|
|
|
|
<text>$($bodyText)</text>
|
|
|
|
<image placement="appLogoOverride" src="$($logo)"/>
|
|
|
|
<image placement="hero" addImageQuery="true" src="C:\Users\User\Pictures\test.jpg"/>
|
|
|
|
</binding>
|
|
|
|
</visual>
|
|
|
|
<audio silent="true"/>
|
|
|
|
</toast>
|
|
|
|
"@
|
|
|
|
|
|
|
|
#play cat mew with notification
|
|
|
|
$MediaPlayer = [Windows.Media.Playback.MediaPlayer, Windows.Media, ContentType = WindowsRuntime]::New()
|
|
|
|
$MediaPlayer.Source = [Windows.Media.Core.MediaSource]::CreateFromUri('https://v1.cdnpk.net/videvo_files/audio/premium/audio0023/watermarked/AnimalCat 6003_40_1_preview.mp3')
|
|
|
|
$MediaPlayer.Volume = 10.
|
|
|
|
$MediaPlayer.Play()
|
|
|
|
|
|
|
|
#show notification
|
|
|
|
$XmlDocument = [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]::New()
|
|
|
|
$XmlDocument.loadXml($xml)
|
|
|
|
$AppId = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
|
|
|
|
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]::CreateToastNotifier($AppId).Show($XmlDocument)
|
2024-08-15 09:51:46 +02:00
|
|
|
|
2024-06-06 13:01:23 +02:00
|
|
|
```
|
2024-08-15 09:51:46 +02:00
|
|
|
|
2024-11-08 12:35:11 +01:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of show-notification-motivation-quote.ps1 as of 11/08/2024 12:34:55)*
|