Hello Jean

Thanks for the hint, it worked! And I managed to create a script that does 
what I want. If there are better or more elegant ways to achieve saving of 
all open files I welcome all feedbacks!

*on* applicationWillSwitchOut(theApp)
*tell* *application* "BBEdit"
*set* allProjects *to* *every* *project document*
*repeat* *with* project *in* allProjects
*set* currentlyOpenDocuments *to* *every* *text document* *of* *window* *of*
 project
*repeat* *with* doc *in* currentlyOpenDocuments
*save* doc
*end* *repeat*
*end* *repeat*
*end* *tell*
*end* applicationWillSwitchOut

Regards, Peter

On Wednesday, August 13, 2025 at 7:32:22 PM UTC+2 jj wrote:

> 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/688fab91-9d16-42e1-8b8b-a46e805c2a86n%40googlegroups.com.

Reply via email to