-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdobePremierePro.ahk
255 lines (233 loc) · 8.29 KB
/
AdobePremierePro.ahk
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
-------------------------------
Adobe Premiere Pro AHK Wrapper
-------------------------------
A basic wrapper for Adobe Premiere Pro using AutoHotkey 2.
This class provides a set of methods to interact with Adobe Premiere Pro.
(c) 2024 Ken Verdadero
2022-06-02
*/
#Requires AutoHotkey v2.0
#Include ../lib/Path.ahk
#Include ../lib/Strings.ahk
class AdobePr {
static AHK_EXE := "ahk_exe Adobe Premiere Pro.exe"
static AHK_CLASS := "ahk_class Premiere Pro"
static AHK_MODAL := "ahk_exe Adobe Premiere Pro.exe ahk_class #32770"
static DIR_PRPROJ := ".prproj"
static CACHED_TITLE := '' ;; Useful for storing title in this variable because modal windows would cause an issue
/* Error Types */
static ErrAbsent(extra) => Error("Premiere is not opened", , extra)
static ErrNoProject(extra) => Error("There is no project opened", , extra)
/**
* Activates Adobe Premiere Pro window
*/
static Activate() {
(AdobePr.isOpened() ? WinActivate(AdobePr.AHK_EXE) : 0)
}
/**
* Returns true if the project is currently opened.
* @returns {Integer}
*/
static IsProjectOpened() {
if WinExist(AdobePr.AHK_EXE) {
try {
title := WinGetTitle(AdobePr.AHK_EXE)
if !StrLen(title) && !AdobePr.IsOnContextMenu() {
AdobePr.CACHED_TITLE := ''
return 0
}
result := (InStr(title, AdobePr.DIR_PRPROJ) ? 1 : 0)
if !result { ;; if a '.prproj' extension is NOT present in title bar, don't update the cached title
return (InStr(AdobePr.CACHED_TITLE, AdobePr.DIR_PRPROJ) ? 1 : 0)
}
AdobePr.CACHED_TITLE := title
return result
}
}
return 0
}
/**
* Returns true if the project is currently rendering.
* @returns {Integer}
*/
static IsRendering() {
try title := WinGetTitle(AdobePr.AHK_EXE)
catch Error {
return 0
}
if AdobePr.IsOnModal() &&
(InStr(title, "Rendering : ") ||
InStr(title, "Rendering Required Audio Files") ||
InStr(title, "Render and Replace")
) {
return 1
}
return 0
}
/**
* Returns true if the project is currently encoding.
* @returns {Integer}
*/
static IsEncoding() {
try title := WinGetTitle(AdobePr.AHK_EXE)
catch Error {
return 0
}
if AdobePr.IsOnModal() && InStr(title, "Encoding ") {
return 1
}
return 0
}
/**
* Returns true if the project is currently saving.
*/
static IsSaving() {
return (AdobePr.IsOnModal() && InStr(WinGetTitle(AdobePr.AHK_EXE), "Save Project", 1) ? 1 : 0)
}
/**
* Returns the title of Adobe Premiere Pro window
* @returns {String} the title
*/
static GetTitle() {
if !AdobePr.IsOpened() {
return ''
}
try {
return WinGetTitle(AdobePr.AHK_EXE)
}
catch Error {
return ''
}
}
/**
* Retrieves information about the current project using the title bar.
* @returns {Object} Returns a metadata/object of the current project
*/
static GetCurrentProject() {
placeholder := {
filename: '',
name: '',
ext: '',
dir: '',
drive: '',
path: '',
saved: ''
}
if AdobePr.IsOnModal() || AdobePr.IsOnContextMenu() || !AdobePr.IsProjectOpened() {
return placeholder
}
try {
title := StrReplace(AdobePr.GetTitle(), '*', '')
filename := StrSplit(title, '\')[-1]
ext := '.' StrSplit(title, '.')[-1]
path := Trim(Join(ArrayTrunc(StrSplit(title, ' '), 6), ' '))
out := {
filename: filename,
name: RegExReplace(filename, ext '$'),
ext: ext,
dir: PathSplit(path)[1],
drive: StrSplit(StrSplit(title, '\')[1], ' ')[-1] '\',
path: path,
saved: (StrSplit(AdobePr.GetTitle())[-1] != '*'),
}
return out
} catch Error {
return placeholder
}
}
/**
* Gets the current position of Adobe Premiere Pro window
* @returns {Array} [X, Y, W, H]
*/
static GetCurrentPos() {
try {
if AdobePr.IsOpened() {
WinGetPos(&X, &Y, &W, &H, AdobePr.AHK_CLASS)
return [X, Y, W, H]
}
throw AdobePr.ErrAbsent("GetCurrentPos")
} catch Error {
return [0, 0, 0, 0]
}
}
static IsSaved() => AdobePr.GetCurrentProject().saved
static IsOnContextMenu() => (WinExist("ahk_class #32768") && AdobePr.IsOpened() ? 1 : 0)
static IsOnModal() => (WinExist("ahk_class #32770") && AdobePr.IsOpened() ? 1 : 0)
static IsOnModalActive() => (WinExist("ahk_class #32770") && AdobePr.IsActive() ? 1 : 0) ;; Probable fix for modal conflicts
static IsOnPopupWindow() => (WinExist("ahk_class DroverLord - Window Class") && AdobePr.IsOpened() ? 1 : 0)
static IsLaunching() => (AdobePr.IsOnModal() && !StrLen(AdobePr.GetTitle()) ? 1 : 0)
static IsOpened() => (WinExist(AdobePr.AHK_EXE) ? 1 : 0)
static IsActive() => (WinActive(AdobePr.AHK_EXE) ? 1 : 0)
static IsOnExportSettings() => (AdobePr.IsOnModal() && AdobePr.GetTitle() == "Export Settings" ? 1 : 0)
static IsOnQuickExportSettings() => (AdobePr.IsOnPopupWindow() && AdobePr.GetTitle() == "OS_PopupWindow" ? 1 : 0)
/**
* Checks if Adobe Premiere Pro is idle and not doing anything.
*/
static IsReady() =>
(AdobePr.IsOpened() && !AdobePr.IsLaunching() &&
!AdobePr.IsOnModal() && !AdobePr.IsOnContextMenu() ? 1 : 0)
/**
* Checks if a balloon popup is present in Adobe Premiere Pro
*/
static HasBalloonPopup(popupType := 0) {
switch popupType {
case 0: color := 0x87BEFF ;; Notice Message
}
if !AdobePr.IsOpened() {
return
}
WinGetPos(&X, &Y, &W, &H, AdobePr.AHK_CLASS)
x := W - (W * 0.1)
y := H - (H * 0.1)
return PixelGetColor(x, y) == color
}
/**
* Focuses a control in Adobe Premiere Pro
*/
static GetControlFocused() {
try return ControlGetClassNN(ControlGetFocus(AdobePr.AHK_EXE))
catch Error {
return 0
}
}
/**
* Adapted from @TaranVH 's `prFocus()` function
* (https://github.com/TaranVH/2nd-keyboard/blob/b0687fe9eaa6d1d33f8e22913b70940c8d78ed0a/Almost_All_Premiere_Functions.ahk#L657)
*
* Focuses to a certain panel.
* * Note: This only works for default keybindings in activating panel.
*
* List of panels:
*
* Shift + 1 - Project Panel
* Shift + 2 - Source Panel
* Shift + 3 - Timeline Panel
* Shift + 4 - Program Panel
* Shift + 5 - Effect Controls Panel
* Shift + 7 - Effects Panel
* Shift + 8 - Media Browser Panel
* Shift + 9 - Audio Clip Mixer Panel
*/
static PanelFocus(panelName) {
if (Type(panelName) != "String") {
throw TypeError("Expected String type, got " Type(panelName), , panelName)
}
if !AdobePr.IsOpened() {
throw AdobePr.ErrAbsent(A_ThisFunc)
}
if !AdobePr.IsProjectOpened() {
throw AdobePr.ErrNoProject(A_ThisFunc)
}
switch StrLower(panelName) {
case 'project': Send("+1")
case 'source': Send("+2")
case 'timeline': Send("+3")
case 'program': Send("+4")
case 'effectcontrols': Send("+5")
; case 'effects': Send("+7") ;; ! This causes to send '&' and idk why
case 'mediabrowser': Send("+8")
case 'audioclipmixer': Send("+9")
}
}
}