* 检查指定应用是否正在运行 * @param appName 应用程序名称 * @returns 是否正在运行
(appName: string)
| 250 | * @returns 是否正在运行 |
| 251 | */ |
| 252 | async isAppRunning(appName: string): Promise<boolean> { |
| 253 | try { |
| 254 | const script = ` |
| 255 | tell application "System Events" |
| 256 | set isRunning to (name of processes) contains "${appName}" |
| 257 | return isRunning |
| 258 | end tell |
| 259 | ` |
| 260 | const result = await this.execute(script) |
| 261 | return result === 'true' |
| 262 | } catch (error) { |
| 263 | console.error(`[AppleScript] 检查应用 ${appName} 运行状态失败:`, error) |
| 264 | return false |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * 退出指定应用程序 |