use AppleScript version "2.8"
use scripting additions
--
on applicationWillSwitchOut(theApp)
tell application "TextEdit"
activate
make new document
set text of front document to "hello applicationWillSwitchOut"
end tell
end applicationWillSwitchOut
use AppleScript version "2.8"
use scripting additions
--
try
tell application "BBEdit"
set vDocuments to its text documents whose modified is true
repeat with vDocument in vDocuments
save vDocument
end repeat
end tell
on error aMessage number aErrorNumber
if aErrorNumber ≠ -128 then -- Error number -128 (User Cancelled).
display dialog aMessage
end if
return
end try
HTH
Jean
You should also avoid using ‘show dialog’ or similar verbs during applicationWillSwitchOut, because that will leave the resulting item on screen until you switch back to BBEdit
Is there a way to write the error into some log file? Or what would be a way to avoid interference with the application switching?