I have an app, myApp, that launches Terminal to do some processing, it works well.
I can quit Terminal manually but I would like to code a Pushbutton in myApp to quit Terminal.
How do I do that?
Tried this…
[code][
Dim TheTerminalApp as FolderItem
TheTerminalApp = SpecialFolder.Applications.Child(“Utilities”).Child(“Terminal.app”)
If TheTerminalApp <> Nil and TheTerminalApp.Exists then
TheTerminalApp.Quit
end if
/code]
It will not compile because “Folderitem” has no member named “Quit”
Your script will attempt to quit even if there are multiple terminal windows open - that might be a problem for some users. Maybe try something like this instead:
tell application “Terminal”
if (get number of windows) is less than 2 then
quit
else
close the front window #assuming that is the window you want to close
end if
end tell
[quote=385630:@Krzysztof Mitko]tell application “Terminal”
if (get number of windows) is less than 2 then
quit
else
close the front window #assuming that is the window you want to close
end if
end tell[/quote]
… and how is that done with no dialogs and no items saved?, I got this, but that will close all windows I think?
set myProcesses to {"Terminal"} -- The ones to quit.
tell application "System Events"
repeat with myProcess in myProcesses
set theID to (unix id of processes whose name is myProcess)
try
-- Should stop the application with no dialogs and no items saved.
do shell script "kill -9 " & theID
end try
end repeat
end tell
Do not use “kill -9 PID”. In case you want to quit via signal use just “kill PID” or “kill -TERM PID”. This ensures that the target application has a chance to clean up.