Better way?: Backup file once an hour.

Discussion in 'Mac Programming' started by VideoBeagle, Apr 23, 2019.

  1. VideoBeagle macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #1
    I've cobbled together an applescript that doesn't quite do what I want to do, but will hopefully get my point across so someone smarter might be able to clue me in.

    Code:
    tell application "System Events" to set isWaterFox to exists (processes where name is "Waterfox")
    
    repeat while isWaterFox
        
        delay 3600
        do shell script "cp '/Users/Scav/Library/Application Support/Waterfox/Profiles/ha4g3an5.default/sessionstore-backups/recovery.jsonlz4' '/Users/Scav/Library/Application Support/Waterfox/Profiles/ha4g3an5.default/emergencybackup/'"
        
       tell application "System Events" to set isWaterFox to exists (processes where name is "Waterfox")  
    
    end repeat
    

    What I want is, When Waterfox is running, once an hour, to make a copy of the session restore file.

    this script seems to do that, but

    1) doesn't seem to stop when Waterfox is closed.
    2) there's likely a better way to do this.

    Can anyone offer thoughts?
     
  2. Krevnik, Apr 24, 2019
    Last edited: Apr 24, 2019

    Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #2
    The variable isWaterFox never gets updated. Your script only sets it once at the start and never checks to see if the process is still running.

    Edit: As for a better way, using a shell script for the whole thing would be less messy.

    Also, you probably want to check the state before you do the backup each time in the loop. Unless you always want one last backup after the process ends?
     
  3. VideoBeagle thread starter macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #3
    I have the query inside the loop as well...that won't update the variable?
    (well obviously it doesn't, but why doesn't it?)

    Yeah, I'm thinking that...looking into how to do that.

    Yeah, I don't need multiple backups.....

    HISTORY: this is the session restore file for Waterfox/Firefox. It's updated throughought usage of the program.
    I have a...bad tab habit. .....sometimes, when the browser hangs badly, rather than record all 5 windows of tabs I have open, it only grabs one...and after a force quit and restart, I've lost all of those pages.

    Firefox/Waterfox has a built in later restore file from when you first open the program for that session...but if you've done lots of closing, opening, etc since you started, yuou've lost all of that.

    So, I'm just wanting an "emergency backup" file if everything built in has failed.
     
  4. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #4
    I didn’t notice it under the “See More”. That’s my fault. So not sure why it doesn’t work unless there’s some variable shadowing or other nonsense happening. I try to avoid AppleScript because it is nearly impossible to debug when something does go wrong (and it will).

    Generally for this sort of watch loop, I use bash and either watch the file itself for changes (via fswatch), or do something similar to what you built here. watchdog with python might be interesting too, as it’s a bit easier to build these sort of scripts with a proper framework and API backing you up.
     
  5. VideoBeagle thread starter macrumors 6502a

    Joined:
    Aug 17, 2010
    Location:
    App Q&A testing by request.
    #5
    Thanks for the tips. I'll look into those.
    I can't have it "when it changes" because it'll grab the "Bad version" of the file when it changes to the missing tabs version, if you see what I'm saying..that's why I went with the "once an hour" idea to cut down the posibility of copying that one.
     

Share This Page

4 April 23, 2019