I just launched the AppleScript itself, I did not use it from any app.
I saw this…
defaults write org.x.X11 wm_auto_quit -bool true
Automatically quit quartz-wm (thus shutting down the X11
server) when the last window is closed.
defaults write org.x.X11 wm_auto_quit_timeout -int 3
Set the timeout for the auto-quit feature. If wm_auto_quit is
true, quartz-wm will wait this many seconds before attempting
to shutdown. If another window is created in that time,
quartz-wm will not shutdown.
Okay, so I was half an hour away from giving up with my super slow VirtualBox Mac testing machine but it finally work.
For the record if anyone try this here are my findings:
Write an AppleScript in my case:
delay 5
tell app "System Events" to shut down
Save it as usual or export it to your project location for project management convenience.
Name it whatever suits you, I named it SDSq.scpt
Open the project
Import/Drag the script onto the project Contents/Navigator.
Now,
For some reason I can’t add Quote in the App.Close so I had to move the code elsewhere, I used my existing timer for this
FolderItem.ShellPath did not work only NativePath
The code in the timer look like so:
If Shutdown Then
#if TargetMacOS Then
Dim k As FolderItem = SpecialFolder.Resources.Child("SDSq.scpt")
If k <> Nil and k.Exists Then
cmd = "osascript """ + k.NativePath + Quote
End If
#Elseif TargetWindows Then
cmd = "shutdown -s -t 15 -c ""Scheduled Shutdown starts in 15 seconds By By"""
#endif
End If
Me.Mode = 0
Quit
In the App.Close event I ended up with this:
If Shutdown Then
dim sh as new Shell
sh.Execute cmd
#If TargetMacOS Then
// Give it two seconds
dim targetTicks as integer = Ticks + 120
while Ticks < targetTicks
App.YieldToNextThread
wend
#endif
End If
Note: in case any other machine is logged on to the target machine you are trying to shut down, the script will never get carried out by itself, a confirmation dialog box pops out and nothing shall happen if no one confirms it.