* 获取当前激活的应用程序信息 * @returns 当前激活应用的信息对象
()
| 61 | * @returns 当前激活应用的信息对象 |
| 62 | */ |
| 63 | async getFrontmostApp(): Promise<{ |
| 64 | name: string |
| 65 | bundleId: string |
| 66 | path: string |
| 67 | } | null> { |
| 68 | try { |
| 69 | const script = ` |
| 70 | tell application "System Events" |
| 71 | set frontApp to first application process whose frontmost is true |
| 72 | set appName to name of frontApp |
| 73 | |
| 74 | -- 获取 Bundle Identifier |
| 75 | set appBundleId to bundle identifier of frontApp |
| 76 | |
| 77 | -- 获取应用路径 |
| 78 | tell application "Finder" |
| 79 | set appPath to POSIX path of (application file id appBundleId as alias) |
| 80 | end tell |
| 81 | |
| 82 | return appName & "|" & appBundleId & "|" & appPath |
| 83 | end tell |
| 84 | ` |
| 85 | const result = await this.execute(script) |
| 86 | |
| 87 | if (result) { |
| 88 | const [name, bundleId, path] = result.split('|') |
| 89 | return { name, bundleId, path } |
| 90 | } |
| 91 | |
| 92 | return null |
| 93 | } catch (error) { |
| 94 | console.error('[AppleScript] 获取当前激活应用失败:', error) |
| 95 | return null |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * 获取当前激活应用的名称(简化版) |