Saturday, May 25, 2019

#1 2005-12-11 01:27:32 pm

Corbin
Member
Registered: 2005-12-05
Posts: 21

Force Quit a given application using applescript?

Is there an applescript term that I can use to Force-Quit a given application,
ie I would like it so when a script is run it Force-Quits say mail.app, not just normal quitting, but force-quitting it so it closes any open documents quickly. Is this possible?

Offline

 

#2 2005-12-11 01:33:21 pm

dkmarsh
Member
Registered: 2005-04-07
Posts: 50

Re: Force Quit a given application using applescript?

Applescript:

tell application "Mail" to quit saving no


Filed under: mail

Offline

 

#3 2005-12-11 01:45:40 pm

Corbin
Member
Registered: 2005-12-05
Posts: 21

Re: Force Quit a given application using applescript?

Will this at as a Force-Quit, what I am looking to do is compile a script that I will set iCal to run at like 3AM that will Force_quit my Mail.app, Safari and iChat, the reason is, often I leve these applications open on accident and if iChat gets a message it prevets iChat from closing, and then stops my entire restart process and I am left in the morning with open windows open asking me if i want to save them. I just want everything closed automaticly.

Offline

 

#4 2005-12-11 07:37:10 pm

dkmarsh
Member
Registered: 2005-04-07
Posts: 50

Re: Force Quit a given application using applescript?

Well, you could always try it and see; that's how I figured out that it works in Mail when unsaved messages being composed are left open. (Haven't had the chance to try it in iChat with an unresponded-to invitation pending, but in Tiger, iChat can be quit with open chats without protesting.)

Offline

 

#5 2005-12-12 09:11:48 am

Matt-Boy
Member
Registered: 2005-10-21
Posts: 480

Re: Force Quit a given application using applescript?

I thought if you could get system events to click on an item in the Dock with control-option and then keystroke an up arrow and then return, you could select "Force Quit" for any app that you specify. So far I can't get it to work. Does anyone know how to click on an item in the dock as if you clicked it with the mouse? I commented out the lines that don't work. This will activate QuarkXPress when I run the script so that much works at least.
Warning: if you try this and uncomment the key down lines, MAKE SURE you uncomment the key UP commands too. Otherwise, the keys stay pressed down even after the script it over!

Applescript:



tell application "System Events"
   tell process "Dock"
       --key down control
       --key down option
       click button "QuarkXPress"
       --key code 126 --up arrow
       --key code 36 --Return
       delay 2
       --key up control
       --key up option
   end tell
end tell
beep 1

Model: Mac G5
Operating System: Mac OS X (10.3.9)

Last edited by Matt-Boy (2005-12-12 09:13:28 am)


Filed under: System

Offline

 

#6 2005-12-12 10:07:38 am

John M
Member
Registered: 2003-07-14
Posts: 387

Re: Force Quit a given application using applescript?

Hi Corbin,

If you want the processes stopped without any dialogs, you could try this approach using the Unix Kill command.

Applescript:

set myProcesses to {"Mail", "Safari", "iChat"} -- 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

Best wishes

John M


Filed under: System

Offline

 

#7 2010-06-10 08:44:03 pm

MikieO
Member
Registered: 2010-06-05
Posts: 1

Re: Force Quit a given application using applescript?

Couldn't you just do something like:

Applescript:

do shell script {"killall Mail", "killall iChat", "killall Safari}

Seem like that'd be the simple way if lists work in shell scripts.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)