Jump to content

Would it be possible to create a script that can autosave files within a timeframe? - (Moved)


Recommended Posts

Posted

The CAD software that I use does not have an autosave option, I have had instances where I have lost files due to losing power and having forgotten to save my work.  I'm looking into ways that I can create a script that can automate the task of Saving in Autodesk Inventor Pro . 

I'm a newbie to writing scripts, would Autoit solve this problem, and where should I start?

  • Developers
Posted

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted (edited)

Here is my idea of how I could do it with Notepad

; https:
;----------------------------------------------------------------------------------------
; Title...........: NotepadAsist.au3
; Description.....: Auto save for Notepad
; AutoIt Version..: 3.3.16.1   Author: ioa747
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <MsgBoxConstants.au3>
#include <Misc.au3>
#include <TrayConstants.au3>

Opt("TrayMenuMode", 3) ; These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.
Global $idExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "GoToExit")
TraySetState($TRAY_ICONSTATE_SHOW)
TraySetIcon(@WindowsDir & "\system32\notepad.exe", 1) ; Set the tray menu icon


;to avoid running it multiple times!
If _Singleton(@ScriptName, 1) = 0 Then Exit

_NotepadAsist()


;----------------------------------------------------------------------------------------
Func GoToExit()    ; exit
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func _NotepadAsist()

    Local $Process_Path = @WindowsDir & "\system32\notepad.exe"
    Local $ProcessStr = "notepad.exe"

    ;Check if $ProcessStr is running else start it
    If Not ProcessExists($ProcessStr) Then
        If FileExists($Process_Path) Then
            Run($Process_Path)
        Else
            MsgBox($MB_SYSTEMMODAL, "Can't find " & $ProcessStr & " to start it", "Please, set the $Process_Path correctly ")
            Exit
        EndIf
    EndIf

    ; Wait 5 seconds for the Notepad window to appear.
    Local $hwNotePad = WinWait("[CLASS:Notepad]", "", 5)

    ; Test if the window exists
    If WinExists($hwNotePad) Then
        ConsoleWrite("- Window exists, $hwNotePad:" & $hwNotePad & @CRLF)

        Local $amPos, $sPos1
        Local $iMouseAutoSave = 0, $iMouseAutoLimit = 30  ; * <- 30 = circa 30 sec            - AutoSave with no Mouse move
        Local $iTimer = 0, $iTimerLimit = 60 * 5          ; * <-  60 * 5 = 300 circa 5 min    - AutoSave Timer

        WinActivate($hwNotePad)

        While WinExists($hwNotePad)
            If WinActive($hwNotePad) Then
                $iTimer += 1
                ConsoleWrite("+ $iTimer=" & $iTimer & @CRLF)

                ;Mouse AutoSave ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                $amPos = MouseGetPos()
                If $sPos1 <> $amPos[0] & ":" & $amPos[1] Then
                    $sPos1 = $amPos[0] & ":" & $amPos[1]
                    $iMouseAutoSave = 0
                    ToolTip("")
                Else
                    ConsoleWrite("  $iMouseAutoSave=" & $iMouseAutoSave & @CRLF)
                    $iMouseAutoSave += 1

                    If $iMouseAutoSave = $iMouseAutoLimit Then  ; * <-
                        $iTimer = 0
                        $iMouseAutoSave = 0
                        ToolTip(" AutoSave in progres...", $amPos[0], $amPos[1])
                        WinActivate($hwNotePad)
                        Send("^s")     ;Ctrl+S for save in notepad
                        Sleep(1000)
                        ToolTip("")
                    ElseIf $iMouseAutoSave > $iMouseAutoLimit - 4 Then
                        ToolTip(" AutoSave in " & ($iMouseAutoLimit - $iMouseAutoSave), $amPos[0], $amPos[1])
                    EndIf
                EndIf

                ;Timer AutoSave ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                If $iTimer = $iTimerLimit Then  ; * <-
                    $iTimer = 0
                    $iMouseAutoSave = 0
                    ToolTip(" AutoSave in progres...", $amPos[0], $amPos[1])
                    WinActivate($hwNotePad)
                    Send("^s")     ;Ctrl+S for save in notepad
                    Sleep(1000)
                    ToolTip("")
                ElseIf $iTimer > $iTimerLimit - 4 Then
                    ToolTip(" AutoSave in " & $iTimerLimit - $iTimer, $amPos[0], $amPos[1])
                EndIf
            Else
                ToolTip("")
            EndIf

            Sleep(1000) ; * <- Master timer
        WEnd

    EndIf

    ConsoleWrite("! Exit - Window does not exist" & @CRLF)

EndFunc   ;==>_NotepadAsist

 

Edited by ioa747
Correction

I know that I know nothing

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...