Hi Peter, Remove the colon and it should work.
*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 HTH, Jean Jourdain On Wednesday, August 13, 2025 at 6:22:10 PM UTC+2 Peter Steiner wrote: > Hello, I'm a seasoned programmer but pretty new to Applescript and BBEdit, > so please bear with me if I'm asking obvious stuff. > > I asked support about auto-save and got a quick answer to look into the ' > applicationWillSwitchOut' attachment point. > > I then found these old threads mentioning applicationWillSwitchOut: > > - https://www.mail-archive.com/[email protected]/msg14492.html > <https://www.mail-archive.com/[email protected]/msg14492.html> > - https://www.mail-archive.com/[email protected]/msg15547.html > <https://www.mail-archive.com/[email protected]/msg15547.html> > > > but without examples (*"This is largely an exercise for the reader :-) > [...], and the group can probably help you with the scripting itself."*) > > To start dabbling with AppleScript I put this compiled script into the > mentioned folder (~/Library/Application Support/BBEdit/Attachment > Scripts/Application.scpt): > > on applicationWillSwitchOut:(theApp) > tell application "TextEdit" > activate > make new document > set text of front document to "hello applicationWillSwitchOut" > end tell > end applicationWillSwitchOut: > > (I made similar subroutines for the other 4 application attachment points) > > I then started BBEdit, switched focus, then back to BBEdit and then quit. > Nothing happened with TextEdit, so I'm not sure if the scripts were even > run. > > Am I doing this wrong? How can I debug attachment scripts? I can't run > them directly in the Script Editor, can I? The manual is silent on this, > probably because mac users are supposed to know that? > > Or even better, has somebody already a script that saves open files when > quitting or switching out? > > Thanks in advance! > > Peter > -- This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "[email protected]" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit> --- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/bbedit/60928568-1339-479c-9c75-e63a0fe949e2n%40googlegroups.com.
