scripting keystrokes in applescript

hello all,

yesterday i worked on my dissertation for quite a while without saving. i did turn on the automatic backup but i think i didnt set the interval to a short enough amount of time, putting all my trust in the stability of my mac.
so anyway, I forgot to save like a dumbass, and duuuh, of course my mac froze pretty much out of nowhere (freaking Transmission may have caused it to freeze i think).

Point being that I lost everything I typed yesterday for my dissertation. Needless to say I was very, very upset (and I’m minding my language !).

So I was wondering if there was a way to script something that could record and export all keystrokes to a text file, which i would ideally launch before working on my paper ?
I would of course like the strokes to be written permanently to the text file so that I still have everything in case the computer freezes…

I found stuff online about system events, but its all for iTunes and other irrelevant things (to me). I found nothing in the dictionaries to be hoenst.

Thanks for any help …

This is not a task for applescript. This kind of continuous recording of activity is a very low level system function. If you do it yourself I bet its at least Objective C/Cocoa or even just a straight C program.
I’d really suggest that you consider a commercial app.


to get used to press ⌘S periodically is easier and almost the same as logging keystrokes :wink:

Uhh, yeah, I ran into these sites while searching google, but I’m not willing to pay for that kind of task. I was pretty sure I could make something with AS …
Whats more, these apps are known to be virus-like, or more like “malicious” – I have no bad intention and I dont care for password recording and stuff like that, which is basically what these were made for : to spy on ppl that use your computer !
and unfortunately, I dont have the programming skills required to code a keylogger either in C or Obj C / Cocoa (nowhere near that good).

Yeah, I know, it seems really stupid because I always DO save by reflex… but when you’re caught into whatever you’re doing and forget, you realize that sh** happens ! and it does NOT only happen to others :stuck_out_tongue:

anyway, upon reading this article here, I really thought there was something I could do …
“reacting to keyboard input” … the guy manages to do something when the keyboard is pressed, isnt there a way to just toss that information into a text file ??

That article is about using code in application X (i.e. the writer’s new, custom application) to sense keys pressed while application X is active. It seems to me that you want application Y to sense keys pressed while application W (or maybe any application (A, B, C, D, .)?) is active. From an event perspective, this is entirely different proposition. I am sure it can be done (things like the KeyboardViewerServer do it), but I am equally sure it is not something to be done purely from AppleScript.

Even if this were possible, having an AppleScript running like this to record keystrokes is painfully slow.

Very true … very true.

Alright, I’ll figure something out, or maybe just buy one of those apps mentionned above :frowning:

use some thing that will auto maticly run an AS every few min then use a keystroke command to save its like auto save but better!.


The other option might be to use something that do autosaves while your are writing drafts at least. That’s when I’m thinking and really into the stuff. I do layout afterwords. - Text edit autosaves, and has the basic facilities for margins
and tables, lists and so on.

Just a thought.

Best Regards