zorg119
zorg119

Reputation: 11

Alternative to 'quit' command

I know the question title looks weird so I'll try to explain it better: I know you can make applications quit by doing this:

tell application "whatever" to quit

I want to know if there are any alternatives to doing this.

Thanks in advance.

Upvotes: 1

Views: 996

Answers (3)

Lri
Lri

Reputation: 27613

delay 5
tell application (path to frontmost application as text) to quit saving no

delay 5
tell application "System Events" to set pid to unix id of (process 1 where frontmost is true)
do shell script "kill " & pid

tell application "TextEdit" to close windows
tell application "System Events" to tell process "TextEdit" to set visible to false
-- Lion will auto-terminate the app

Upvotes: 1

sakra
sakra

Reputation: 65751

The problem with the tell application "whatever" to quit approach is that you can only target applications that are installed on your machine upon compilation of the script. Here's an AppleScript that determines the names of all running application processes and then quits each one by sending it the quit command.

property pExcludeApps : {"Finder", name of current application}

tell application "System Events"
    set theAppsToQuit to name of every process where background only = false
end tell

repeat with theApp in theAppsToQuit
    if pExcludeApps does not contain contents of theApp then
        tell application (contents of theApp)
            quit saving yes
        end tell
    end if
end repeat

Upvotes: 1

fireshadow52
fireshadow52

Reputation: 6516

You could use GUI Scripting like this...

tell application "System Events" to tell process "whatever" to keystroke "q" using {command down}

Upvotes: 1

Related Questions