@@ -31,40 +31,39 @@ async function osacompile(compileTarget: string): Promise<void> {
3131 return ;
3232 }
3333
34- doc . save ( ) . then ( ( ) => {
35- const outName = getOutName ( doc . fileName , compileTarget ) ;
36- const args : string [ ] = [ '-o' , outName ] ;
34+ await doc . save ( ) ;
3735
38- if ( options . executeOnly === true ) {
39- args . push ( '-x' ) ;
40- }
36+ const outName = getOutName ( doc . fileName , compileTarget ) ;
37+ const args : string [ ] = [ '-o' , outName ] ;
4138
42- if ( compileTarget === 'app' && options . stayOpen === true ) {
43- args . push ( '-s' ) ;
44- }
39+ if ( options . executeOnly === true ) {
40+ args . push ( '-x' ) ;
41+ }
42+
43+ if ( compileTarget === 'app' && options . stayOpen === true ) {
44+ args . push ( '-s' ) ;
45+ }
4546
46- if ( compileTarget === 'app' && options . startupScreen === true ) {
47- args . push ( '-u' ) ;
47+ if ( compileTarget === 'app' && options . startupScreen === true ) {
48+ args . push ( '-u' ) ;
49+ }
50+
51+ args . push ( doc . fileName ) ;
52+
53+ try {
54+ await spawnPromise ( 'osacompile' , doc . fileName , args , outputChannel ) ;
55+ if ( showNotifications ) {
56+ window . showInformationMessage ( `Successfully compiled '${ doc . fileName } '` ) ;
4857 }
58+ } catch ( error ) {
59+ console . error ( '[idleberg.applescript]' , error instanceof Error ? error . message : error ) ;
4960
50- args . push ( doc . fileName ) ;
61+ outputChannel . show ( ) ;
5162
52- spawnPromise ( 'osacompile' , doc . fileName , args , outputChannel )
53- . then ( ( ) => {
54- if ( showNotifications ) {
55- window . showInformationMessage ( `Successfully compiled '${ doc . fileName } '` ) ;
56- }
57- } )
58- . catch ( ( error ) => {
59- console . error ( '[idleberg.applescript]' , error instanceof Error ? error . message : error ) ;
60-
61- outputChannel . show ( ) ;
62-
63- if ( showNotifications ) {
64- window . showErrorMessage ( 'Failed to compile or exited with error (see output for details)' ) ;
65- }
66- } ) ;
67- } ) ;
63+ if ( showNotifications ) {
64+ window . showErrorMessage ( 'Failed to compile or exited with error (see output for details)' ) ;
65+ }
66+ }
6867}
6968
7069async function osascript ( ) : Promise < void > {
@@ -98,14 +97,16 @@ async function osascript(): Promise<void> {
9897 args . unshift ( '-s' , osascript . outputStyle . trim ( ) ) ;
9998 }
10099
101- spawnPromise ( 'osascript' , doc . fileName , args , outputChannel ) . catch ( ( error ) => {
100+ try {
101+ await spawnPromise ( 'osascript' , doc . fileName , args , outputChannel ) ;
102+ } catch ( error ) {
102103 console . error ( '[idleberg.applescript]' , error instanceof Error ? error . message : error ) ;
103104 outputChannel . show ( ) ;
104105
105106 if ( showNotifications ) {
106107 window . showErrorMessage ( 'Failed to run script or exited with error (see output for details)' ) ;
107108 }
108- } ) ;
109+ }
109110}
110111
111112/**
0 commit comments