Skip to content

Commit f12c98c

Browse files
committed
Add screenshot feature
1 parent e8f7e75 commit f12c98c

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

.github/workflows/screenshot_demo.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Create a simple workflow to take a screenshot of the Windows worker's desktop
2+
name: Screenshot
3+
on:
4+
workflow_dispatch:
5+
jobs:
6+
screenshot:
7+
runs-on: windows-latest
8+
steps:
9+
- name: "Checkout"
10+
uses: actions/checkout@v4
11+
- name: "Take Screenshot"
12+
run: |
13+
# Take a screenshot of the Office application
14+
. "./scripts/utils/Screenshot.ps1"
15+
Take-Screenshot -OutputPath "Screenshot.png"
16+
- name: "Upload Screenshot"
17+
uses: actions/upload-artifact@v4
18+
with:
19+
name: "Screenshot"
20+
path: "screenshot.png"

scripts/Build-VBA.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ $basFiles | ForEach-Object {
156156
}
157157
}
158158

159+
# Take a screenshot of the Office application
160+
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
161+
. "$scriptPath/utils/Screenshot.ps1"
162+
Take-Screenshot -OutputPath "${outputDir}Screenshot_${fileNameNoExt}.png"
163+
159164
# Save the document
160165
$doc.Save()
161166
# Close the document

scripts/utils/Screenshot.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function Take-Screenshot {
2+
param (
3+
[Parameter(Mandatory=$true)]
4+
[string]$OutputPath
5+
)
6+
7+
Add-Type -AssemblyName System.Windows.Forms
8+
Add-Type -AssemblyName System.Drawing
9+
10+
# Get the screen dimensions
11+
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
12+
$bounds = $screen.Bounds
13+
14+
# Create a bitmap of the screen size
15+
$bitmap = New-Object System.Drawing.Bitmap $bounds.Width, $bounds.Height
16+
17+
# Create a graphics object from the bitmap
18+
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
19+
20+
# Copy the screen to the bitmap
21+
$graphic.CopyFromScreen($bounds.X, $bounds.Y, 0, 0, $bounds.Size)
22+
23+
# Save the bitmap as a file
24+
$bitmap.Save($OutputPath)
25+
26+
# Dispose of the objects
27+
$graphic.Dispose()
28+
$bitmap.Dispose()
29+
30+
Write-Host "Screenshot saved to: $OutputPath"
31+
}

0 commit comments

Comments
 (0)