TeXShop autosave

My laptop overheated today, failed to wake from sleep, and eventually shut down. I lost some work in TeXShop. If it would auto-save this wouldn’t have been a problem. I’m sure this filthy hack has numerous problems, so please feel free to tell me about them in the comments.

$ defaults write TeXShop KeepBackup YES

TSDocument.h
- (void)mySaveTimer: (NSNotification *)aNotification;

TSDocument.m
//At the end of init,
[NSTimer scheduledTimerWithTimeInterval:300.0 // 300 seconds = 5 mins
target:self
selector:@selector(mySaveTimer:)
userInfo:nil
repeats:YES];

// At the end of the file
- (void)mySaveTimer: (NSNotification *)aNotification
{
// [GARETH] Just copy/pasted the content of -saveDocument, and replaced "sender" with "self" in this first line,
[super saveDocument: self];

// if CommandCompletion list is being saved, reload it.
if (!fileIsTex && [[self fileName] isEqualToString:
[CommandCompletionPath stringByStandardizingPath]])
[[NSApp delegate] finishCommandCompletionConfigure];
}

For reference,

“Configuring Run Loop Sources – Configuring Timer Sources”
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html

“NSTimer Class Reference”
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html%23//apple_ref/doc/uid/TP40003747

“keepBackupFile”
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSDocument_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSDocument/keepBackupFile

Advertisements

3 thoughts on “TeXShop autosave

  1. Far too complicated, this is all that’s needed,

    TSDocumentController.m
    //Inside -init()
    [self setAutosavingDelay:300.0]; // 300 sec = 5 mins

    For reference,
    http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Documents/Articles/Autosaving.html

    By default the file is saved with the same path, but with ” (Autosaved)” added before the file extension.
    ~/Library/Autosave Information/TeXShop.plist contains data that records which files were autosaved.
    Note also that auto-saved files are automatically restored when the application’s reopened.

    • This could probably be implemented as a “hidden” preference flag, just like keepBackupFile, but with a floating point number to specify the delay in seconds (rather than being hardcoded to 300s = 5 min as posted here.)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s