@@ -57,6 +57,12 @@ function runWindowsHotkey(keys: string[]): void {
5757 const keyCode = virtualKeys [ key ] ?? key . toUpperCase ( ) . charCodeAt ( 0 )
5858 const script = [
5959 `Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public static class NativeKeyboard { [DllImport("user32.dll")] public static extern void keybd_event(byte key, byte scan, uint flags, UIntPtr extra); }'` ,
60+ '$notepad = Get-Process -Name notepad -ErrorAction SilentlyContinue | Sort-Object StartTime -Descending | Select-Object -First 1' ,
61+ 'if ($notepad) {' ,
62+ ' $shell = New-Object -ComObject WScript.Shell' ,
63+ ' if (-not $shell.AppActivate($notepad.Id)) { throw "Notepad window could not be activated" }' ,
64+ ' Start-Sleep -Milliseconds 200' ,
65+ '}' ,
6066 ...modifiers . map ( ( modifier ) => `[NativeKeyboard]::keybd_event(${ virtualKeys [ modifier ] } , 0, 0, [UIntPtr]::Zero)` ) ,
6167 'Start-Sleep -Milliseconds 100' ,
6268 `[NativeKeyboard]::keybd_event(${ keyCode } , 0, 0, [UIntPtr]::Zero)` ,
@@ -205,8 +211,13 @@ export function saveNativeFile(platform: Platform, paths: RunPaths, candidatePat
205211 const script = [
206212 'on run argv' ,
207213 'tell application "System Events"' ,
208- 'set frontmost of first application process whose unix id is (item 3 of argv as integer) to true' ,
209- 'delay 0.5' ,
214+ 'set targetProcess to first application process whose unix id is (item 3 of argv as integer)' ,
215+ 'set frontmost of targetProcess to true' ,
216+ 'repeat 50 times' ,
217+ 'if (count of sheets of windows of targetProcess) > 0 then exit repeat' ,
218+ 'delay 0.2' ,
219+ 'end repeat' ,
220+ 'if (count of sheets of windows of targetProcess) is 0 then error "Native save dialog was not found"' ,
210221 'keystroke "g" using {command down, shift down}' ,
211222 'delay 1' ,
212223 'keystroke (item 1 of argv)' ,
0 commit comments