* 获取所有运行中的应用程序列表 * @returns 运行中的应用程序名称数组
()
| 225 | * @returns 运行中的应用程序名称数组 |
| 226 | */ |
| 227 | async getRunningApps(): Promise<string[]> { |
| 228 | try { |
| 229 | const script = ` |
| 230 | tell application "System Events" |
| 231 | set appList to name of every application process |
| 232 | return appList as text |
| 233 | end tell |
| 234 | ` |
| 235 | const result = await this.execute(script) |
| 236 | if (result) { |
| 237 | // AppleScript 返回的列表用逗号分隔 |
| 238 | return result.split(', ').filter((name) => name.trim()) |
| 239 | } |
| 240 | return [] |
| 241 | } catch (error) { |
| 242 | console.error('[AppleScript] 获取运行中应用列表失败:', error) |
| 243 | return [] |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * 检查指定应用是否正在运行 |