Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there any way I can programatically determine whether a notebook has unsaved edits?

Is that asterisk on the right of the notebook name represented in a notebook option or something, like HasUnsavedEdits?

share|improve this question
    
As you suspected, the asterisk to the right of the notebook file name only appears when there are unsaved edits. –  Eli Lansey Feb 2 '12 at 17:12
    
I know, I wanna know if I can programatically ask if the notebook "has the asterisk". Just edited to make it clear, my bad –  Rojo Feb 2 '12 at 17:14
    
Ah, OK. The edits clarified the question. –  Eli Lansey Feb 2 '12 at 17:19
    
I'm curious what your need for this is. Care to share? –  Eli Lansey Feb 2 '12 at 17:37
1  
@EliLansey I am adding a little function on my personal package of helper functions, to allow for automatic backuping of notebooks. You can set up the frequency of saves, if you want backup copies on a subdirectory, how often do you want them, and of course, stop the task... I wanted this info to avoid backing up a file again that hasn't changed since the last backup. "FileModificationTime" and "MemoryModificationTime" also come in handy. I hate not having undos, and having powercuts and blue screens of death –  Rojo Feb 2 '12 at 17:50
show 1 more comment

1 Answer

up vote 14 down vote accepted

I think that

"ModifiedInMemory" /. NotebookInformation@SelectedNotebook[]

does what you want (ie, returns False if the notebook is saved, True if it is not saved). Although maybe not quite, try NotebookInformation[CreateDocument["hi"]]

But it seems to work once you modify a notebook that's been saved once. I could be wrong though...

share|improve this answer
    
Yeah, thanks. I didn't know about NotebookInformation –  Rojo Feb 2 '12 at 17:22
    
The document you created that way doesn't have the asterisk, nor pops up the Save Us dialog when you close it. It's a weird behaviour, but that information is exactly what I was looking for –  Rojo Feb 2 '12 at 17:28
    
@Rojo there are notebook options that you can for these things, I think. But I'm not that familiar with this sort of thing. Thanks for the accept –  acl Feb 2 '12 at 17:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.