I have seen a few people mention the possibility of saving workflows without data, for example:
I ran into the problem myself a couple of times today where I had created workflows with a relatively large amount of data and then out of habit hit Ctrl-S. The first time it inconvenienced me for a few minutes, but the second time this happened, I found that 30 minutes later my KNIME was still out of action, and as I was only testing some ideas, I decided to go kill it from Task Manager [hands over ears “la la la”] because it seemed to be getting nowhere fast.
So it got me thinking, how could I prevent this situation from occurring a third time? I don’t want to get out of the habit of pressing Ctrl-S periodically, but likewise I don’t want to make my KNIME unusable for large amounts of time.
What I needed was a way to trap Ctrl-S, and have it give me the possibility of saving without data, or at least warn me, so I could decide what I wanted to do (i.e. reset my workflow and then save, or save it with data intact - and go read a book!). I decided that my solution also needed to deal with Ctrl-Shift-S (save all) in some way too.
I have used an application called AutoHotKey in the past, and I wondered if it could assist me here. (It is a free open source application that can trap key presses, and take action on them)
After some experimentation, I decided it could, and I put together the following script:
AutoHotKey script
/* Auto Hot Key script to trap Ctrl-S pressed in KNIME.exe
Gives the user the option of resetting the workflow prior to saving
This helps avoid large wait time for saving of large data sets with workflow
Script written by @takbb Brian Bates - 18 May 2021
This script is free to use for any use
Use at your own risk - There is no cast-iron guarantee that it will always prevent unwanted saving of workflow data
but it will hopefully help.
To use this script, install AutoHotKey - available from autohotkey.com
Place it in same folder as a copy of AutoHotKey.exe
rename AutoHotKey.exe as KnimeSaveAfterReset.exe (i.e. the same name, but with .exe extension as this script)
and run at either at Windows Startup, or priot to running Knime.exe
*/
;TrayTip, AutoHotKey, Looking for KNIME Analytics Platform - Ctrl S press , 16
SetTitleMatchMode 3 ; window title equals
loop {
#IfWinActive ahk_exe knime.exe
^+s::
MsgBox, 1,"KNIME Ctrl-Shift-S Pressed (detected by AHK script)", "This will save ALL unsaved workflows including data. Are you sure?"
ifMsgBox OK
{
Send ^+s
}
else
{
MsgBox 0, "KNIME - AutoHotKey", "Workflow(s) not saved"
}
return
^s::
MsgBox, 3,"KNIME Ctrl-S Pressed (detected by AHK script)", "Do you want to reset the workflow before saving, to avoid saving data?
ifMsgBox Yes
{
Sleep, 30
Send ^{a}
Sleep, 1000
Send {F8}
Sleep, 1000
Send ^{s}
}
else
{
IfMsgBox No
{
Send ^{s}
}
else
{
MsgBox 0, "KNIME - AutoHotKey", "Workflow not saved"
}
}
return
}
I have uploaded it here as a text file too.
KnimeSaveAfterReset.ahk.txt (1.6 KB)
If you are interested and want to try it with AutoHotKey, save it somewhere and remove the .txt extension, so that it just becomes KnimeSaveAfterReset.ahk
Obviously you’ll need to download and install AutoHotKey too.
With AutoHotKey (AHK) installed on my pc, I can either run the KnimeSaveAfterReset.ahk file manually by double-clicking it, in which case AHK will run the script in my system tray, or alternatively I can place a copy of AutoHotKey.exe in the same folder as KnimeSaveAfterReset.ahk, and then rename the AutoHotKey.exe as KnimeSaveAfterReset.exe. In that case, executing the KnimeSaveAfterReset.exe will run AHK and automatically run the .ahk script, which is quite cool. In this way it can be set to run at Windows startup, and no messing with command line parameters!
Once running it sits there waiting for Ctrl-S or Ctrl-Shift-S to be pressed. If they are pressed outside of Knime, it ignores the presses. A line in the script tells it to only be interested if the active application is Knime.exe.
To provide some demo screenshots here, I have a demo Data Generator which is set to generate a 5000 rows and then does a cross join, thus creating 25 million rows. That’s enough to demo the effect.
Ctrl-S (Save)
Now if I press Ctrl-S, then instead of Knime saving straight away, the following dialog appears:
If I press Cancel, it blocks the save, but the workflow remains with its data intact:
If I choose Yes, it issues a Ctrl-A (select all), F8 (reset), and finally Ctrl-S to save, thus sparing me several minutes wait that I didn’t want. It does a short wait between button presses. That seems to work on my system. It would be good to get feedback about whether this works for other people, or if any tweaking is required.
If I choose No, it does the Ctrl-S, as it would have done, and saves the data while I go get a coffee (or write an article about AutoHotKey on the Knime forum).
(to be fair, 25 million rows didn’t even allow me to get downstairs and fill the kettle, but you get my point!)
Ctrl-Shift-S (Save All)
Trapping Save All was also something I decided it should do, although it isn’t so common for me to do that key press. In this case I cannot easily go through each workflow and reset, so I thought at least it should give a warning, and allowing the option of not doing the action.
So pressing Ctrl-Shift-S results in the following dialog:
Pressing OK will continue with the action (AHK will send a repeat Ctrl-Shift-S to KNIME).
Pressing Cancel will result in the workflows not being saved, and the following warning dialog being displayed. I can then go through and reset individually any workflows that have large amounts of data:
Obviously this is only trapping Ctrl-S and Ctrl-Shift-S. It cannot trap the use of the File-Save and File-Save All, and nor can it trap the pressing of the Save icons on the toolbar. If you use those, then this isn’t really going to help. Sorry!
Likewise, if you don’t want to be resetting your data when you save then this isn’t for you either (although it doesn’t prevent you doing so, so perhaps having the option presented each time might still benefit you).
I strongly advise though using the Auto Save feature built into Knime (and having Save data switched off on that option). Perhaps with that plus this, you have the best of both worlds. You can rely on Auto Save to protect you from disaster, and this key-press trap stops you tying up your pc when you don’t want to!
If you are like me, and just naturally press Ctrl-S periodically without giving it a second-thought, then maybe you too will find this useful if you are often working with large data sets. But it does mean I might cut down on coffee…
Enjoy (or ignore ) as you see fit!