-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathImageCapture-Interactive.ps1
113 lines (101 loc) · 3.58 KB
/
ImageCapture-Interactive.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
#---------------------------------------------------------------------------
# This is a Powershell sample application to demonstrates how to
# perform a Snagit COM image capture and save it to a file.
# The image can be previewed in the Snagit Editor if you decide so.
# Note: This code is backward compatible clear back to Snagit 8.1.0.
#
# Support e-mail: [email protected]
# This software is provided under the MIT License (http://opensource.org/licenses/MIT)
# Copyright (c) 2015 TechSmith Corporation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sub-license, and/or sell copies of the Software, and to permit persons
# to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#---------------------------------------------------------------------------
# PowerShell can't import type library from a COM Object
# See http://msdn.microsoft.com/en-us/library/hh228154.aspx
# So let's import those enums from a separate powershell script
. .\Snagit_enums.ps1
$object = New-Object -ComObject SNAGIT.ImageCapture
#
# set the input
#
write-host
foreach ($v in [enum]::GetValues([snagImageInput]))
{
write-host ([int]$v) for $v
}
$object.Input = [snagImageInput](Read-Host "`nWhat input do you want to use?");
#
# set the output
#
write-host
foreach ($v in [enum]::GetValues([snagImageOutput]))
{
write-host ([int]$v) for $v
}
$object.Output = [snagImageOutput](Read-Host "`nWhat output do you want to use?");
#
# Preview or no preview?
#
if ( $object.Output -ne [snagImageOutput]::sioNone )
{
$object.EnablePreviewWindow = [Int32](Read-Host "`nEnable Preview (0:no preview, 1:with preview)?");
}
else
{
$object.EnablePreviewWindow = $true
}
#
# Set file type (if output is File, Mail or FTP)
#
if ( $object.Output -eq [snagImageOutput]::sioFile -Or
$object.Output -eq [snagImageOutput]::sioMail -Or
$object.Output -eq [snagImageOutput]::sioFTP )
{
write-host
foreach ($v in [enum]::GetValues([snagImageFileType]))
{
write-host ([int]$v) for $v
}
$object.OutputImageFile.LoadImageDefaults( [snagImageFileType](Read-Host "`nWhat file type do you want to use?") )
#
# Set File Naming method to auto
#
$object.OutputImageFile.FileNamingMethod = [snagOuputFileNamingMethod]::sofnmAuto;
}
#
# Set output directory to TEMP
#
$object.OutputImageFile.Directory = $env:Temp
#
# trigger the capture
#
$object.Capture()
#
# Wait until the capture is done
#
while (!$object.IsCaptureDone)
{
sleep 1
}
if ( $object.Output -eq ([snagImageOutput]::sioFile) )
{
write-host "File written: " $object.LastFileWritten
}
"`nDone"
# pause if needed
if ($host.name -eq 'ConsoleHost')
{
Write-Host "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}