Detect whether a document has been Edited since last saved?

Wondering if KM can detect whether a document is in an Edited/Unsaved state?

For Example:

Title of front window in TextEdit currently looks like this:

I tried this:

But to no avail -- it returns false rather than true. (Meaning, I assume, that '--Edited' is not technically part of the window title.)

If anyone can tell me whether or not there is something in KM that can detect the document's Saved/Edited state, I would very much appreciate it. Thanks.

The only way I can see would be a screen search, which wouldn’t work well since you could have multiple edited windows visible.

What about checking if the Save menu is enabled or not?

Yes, you would think that would work, but TextEdit at least leaves the Save menu permanently enabled, even when no save is required (poor programming, but it is Apple, so I suppose they can do what they like).

Thanks for the help, Phillippe and Peter. Hopefully some day Apple will toggle the state of the Save menu item appropriately.

Is there a way I’m unaware of to detect a file’s ‘Edited’ state via AppleScript? (I’m assuming the answer is ‘no’, so no need to reply unless my assumption is incorrect.)

Thanks again.


So, it looks like the File > ’Revert to’ menu will have n == 1 items if it’s currently in an unchanged state, and will have n >= 2 items if it’s modified and unsaved. I just started using KM a couple of days ago, so unfortunately, I don’t know how to proceed with that information, but if you do figure it out, please post the solution as I think the general workflow for this would be really useful!


1 Like

Ahh, good catch. In that case you can use the "Menu with name matching ‘^Last Saved.*’ is enabled" condition.

A good catch, indeed – thanks woof; improved one of my macros vastly. Much appreciated.

Peter, forgive my naivete, but can I ask what function the “^” preceding “Last Saved” serves? (I am guessing that the “.*” following it is Regex for ‘any number of any characters’, but I am not entirely certain.)

Thanks very much.

1 Like

^ means “at the start”
. means “any character”

  • means "zero or more of the preceding element.

So the regular expression matches:

[at the start only]Last Saved[zero or more any characters]

1 Like

Got it. Thanks you, sir.

1 Like

You would think that the modified property of a document would tell you, but with both Script Editor and TextEdit, modified of the front document is false even after typing a character in that document. I haven’t tried other applications. Can someone explain this?

I’m getting inconsistent, and in some cases somewhat mysterious, results across applications:


  • Unmodified document:

  • Type a character:

Script Editor

  • Unmodified document:
  • Type a character.

Script Debugger

  • Unmodified Document:
  • Type a character:
    Menu item unchanged.


  • Unmodified Document:
  • Type a character:

I could go on.

In most cases checking the state of the buttons at the extreme upper left of the window works (I had to snapshot all three and set fuzziness all the way to the left to get it to work), but not all: in Xcode, the button doesn't change when a file is modified.

Also, you would expect the File>Save menu item to be grayed out when there are no modifications, but that isn’t the case — at least I haven't noticed an application where it is. Upon reflection, though this was always right in front of my face, it does seem bizarre.

Hey Mitchell,

Apple’s Versions purely sucks.

I have it turned off as much as possible.

And the modified property works fine for me in both TextEdit and Script Editor.


That’s really weird. I certainly expected them to do so, but they don't for me. All I did was type a character in a saved file then did something like

the modified of the front document of application "TextEdit"

How? I never use it, but it does sometimes get in the way, especially with files that haven’t been saved for the first time.

Hey Mitchell,

System Prefs > General

Google “os x how to turn off versions”

I was thinking I'd used Onyx or TinkerTool System to turn off app-nap and a couple of other things, but I'm not finding those features in either app.


What do those have to do with versions?