Auto save script

Hi all, this is my first post obviously.
I’m very new to Applescript and I’d like to know if there is a place I can find a script to auto save all open window in all open apps, or at least display the save dialog. If there is not one available is it possible to write one?
This is for OS X by the way.

Thanks for any feedback

AppleScript works by targeting specific applications and telling them to perform tasks.

While in theory it’s possible to loop through all applications, the success (or otherwise) of your script will depend on how much AppleScript support the developers have added to the applications. Trying to tell a non-scriptable application to save a document will cause an error.

The closest I think you can get is using a ‘try’ block to catch the errors, and ignore them so they don’t interfere with the flow of your script.

Something like this should get you going:

-- first, get all running apps:
tell application "System Events" 
   -- find running apps
   -- note the use of the 'whose' clause to only show UI apps, not background tasks
   set runningApps to name of every application process whose visible is true
end tell

-- now loop through each application
repeat with eachApp in runningApps
   try -- here's the try statement
      tell application eachApp -- tell each app in turn
         save every document
      end tell
   on error -- if the above statement fails...
   -- do nothing - just ignore the error and move on 
   end try
end repeat

Note, however, that the script may still have problems if specific apps have a different interpretation of the ‘save’ command. For example, some applications such as Safari don’t have disk-based documents and require a file specification to be provided if you want to save a web page (otherwise it doesn’t know where to save the document). The behavior of unsaved documents (where the app would normally prompt for a filename) is also unspecified.

You might be safer generating a list of the specific applications that you want to save, and that use the normal ‘save’ terminology and walk through that list rather than all applications.