Obsidian
按下快捷键打开指定软件:
1
2
3
4
5
|
; 定义快捷键 Alt+1
!1::
; 启动Obsidian软件
Run, C:\Users\Dell\AppData\Local\Programs\obsidian\obsidian.exe
return
|
如果 Obsidian 软件已经打开了,我不需要再次打开,只需要切换到这个软件即可,那么代码该如何调整
如果你只想在 Obsidian 软件已经打开的情况下切换到它,你可以使用 IfWinExist
和 WinActivate
来实现。下面是一个修改过的示例脚本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
; 定义快捷键 Alt+1
!1::
; 检查Obsidian是否已经打开
IfWinExist, ahk_exe obsidian.exe
{
; 如果已经打开,激活Obsidian窗口
WinActivate
}
else
{
; 如果未打开,启动Obsidian软件
Run, C:\Users\Dell\AppData\Local\Programs\obsidian\obsidian.exe
}
return
|
Chrome
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
; 定义快捷键 Alt+2
!2::
; 检查Chrome是否已经打开
IfWinExist, ahk_exe chrome.exe
{
; 如果已经打开,激活Chrome窗口
WinActivate
}
else
{
; 如果未打开,启动Chrome软件
Run, C:\Program Files\Google\Chrome\Application\chrome.exe
}
return
|
Solidworks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
; 定义快捷键 Alt+3
!3::
; 检查SolidWorks是否已经打开
IfWinExist, ahk_exe SLDWORKS.exe
{
; 如果已经打开,激活SolidWorks窗口
WinActivate
}
else
{
; 如果未打开,启动SolidWorks软件
Run, D:\Program Files\SOLIDWORKS Corp\SOLIDWORKS\SLDWORKS.exe
}
return
|
小结
按下快捷键打开指定软件,若程序已打开则激活窗口
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
|
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; 定义程序路径
obsidianPath := "C:\Users\Administrator\AppData\Local\Obsidian\Obsidian.exe"
chromePath := "C:\Program Files\Google\Chrome\Application\chrome.exe"
solidworksPath := "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\SOLIDWORKS 2021\SOLIDWORKS 2021"
; 定义快捷键 Alt+1
!1::
; 检查Obsidian是否已经打开
IfWinExist, ahk_exe obsidian.exe
{
; 如果已经打开,激活Obsidian窗口
WinActivate
}
else
{
; 如果未打开,启动Obsidian软件
Run, %obsidianPath%
}
return
; -------------打开Chrome-------------
; 定义快捷键 Alt+2
!2::
; 检查Chrome是否已经打开
IfWinExist, ahk_exe chrome.exe
{
; 如果已经打开,激活Chrome窗口
WinActivate
}
else
{
; 如果未打开,启动Chrome软件
Run, %chromePath%
}
return
; -------------打开Solidworks-------------
; 定义快捷键 Alt+3
!3::
; 检查SolidWorks是否已经打开
IfWinExist, ahk_exe SLDWORKS.exe
{
; 如果已经打开,激活SolidWorks窗口
WinActivate
}
else
{
; 如果未打开,启动SolidWorks软件
Run, %solidworksPath%
}
return
|