Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

VideoBeagle

macrumors 6502a
Original poster
Aug 17, 2010
823
18
App Q&A testing by request.
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?
 
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?
 
Last edited:
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.

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?)

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

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

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?

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.
 
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?)

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.