Article ID: 172079
Article Last Modified on 6/29/2004
-- Start of script code. The "--" string is a comment indicator
on run (tcAppName)
set lcNoParameter to "No parameter given as application to close."
set lcEmptyParameter to "No application specified to close."
-- Check for missing parameter or incorrect data type
try
set tcAppName to tcAppName as string
on error errmsg number errnum
if errnum = -1700 then
display dialog lcNoParameter
return
end if
end try
-- Check for empty parameter string
if tcAppName = "" then
display dialog lcEmptyParameter
return
else
-- Store passed app name to variable
set cAppName to tcAppName
end if
tell application "Finder"
-- Create list of running applications - these are object data
set lstResult to name of every process
end tell
-- Loop thru all open apps
repeat with oAppObj in lstResult
-- Check if name matches parameter passed to script
if (oAppObj as string) is cAppName then
-- If so, activate, which will cause app to prompt for save,
-- then quit.
tell application cAppName
activate
-- Use try then on error to trap for Cancel from Save dialog
try
with timeout of 10 seconds
quit
end timeout
on error errmsg number errnum
end try
end tell
end if
end repeat
end run
-- End of script code
RUNSCRIPT "MACINTOSH HD:APPLE'S SCRIPTING SYSTEM:KillAppIfRunning"
with "Microsoft Word"Keywords: kbhowto kbcode KB172079