-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRun.ahk
53 lines (46 loc) · 1.51 KB
/
Run.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
/*
Extended library for Run
(c) 2022-2024 Ken Verdadero
2022-06-02
*/
/**
* Run a command and return the output
* @param command The command to run
* @returns {Buffer|String} The output of the command
*/
RunWaitOne(command) {
FN := A_TickCount
shell := ComObject("WScript.Shell")
cmd := Format('{1} /c {2} > {3}\{4}.txt', A_ComSpec, command, A_Temp, FN)
exec := shell.Run(cmd, 0, true)
OUT := FileRead(Format("{1}\{2}.txt", A_Temp, FN))
FileDelete(Format("{1}\{2}.txt", A_Temp, FN))
return OUT
}
/**
* Evaluate an arithmetic expression using the `cmd` command.
* @param expression {String} - The arithmetic expression to evaluate.
* @returns {Buffer|String} - The result of the arithmetic expression.
*/
EvalArithmetic(expression) => RunWaitOne(Format('set /a {1}', expression))
/**
* Run or activate a window.
*
* If the window is not found, it will run the process.
* If the window is found, it will activate the window.
*
* @param Target the target window title
* @param Proc the process to run
* @param {Integer} AllowMultiInstance if true, it will run the process even if the window is found.
*/
RunActivate(Target, Proc, AllowMultiInstance := false) {
(WinExist(Target) ? (AllowMultiInstance ? Run(Proc) : WinActivate(Target)) : Run(Proc))
}
/**
* Opens the properties window of the file
* @param path The path of the filecmd /c
*/
RunProperties(path) {
shell := ComObject("shell.application")
shell.namespace(0).parsename(path).invokeverb("Properties")
}