Neither one nor Many

 
June 6 2013

Hook shortcut keys Ctrl+Alt+{0,1,2,3,4,5,6,7,8,9}

sanitizer.exe is a program that reads a config, and then registers the hotkeys Ctrl+Alt+{number}, where {number} is {0, 1, ..., 9}.

Example contents for config.ini:

[1]
type=command
value=putty -load SomeSession

[4]
type=clipbard
value=MyMysqlPasswd

[6]
type=explorer

...

(Only [0] through [9] are valid entries in the config.)

As shown in the example, available action types are:

action types description example
command execute system call putty.exe -load amazon
clipboard replace clipboard with text some database password perhaps
explorer dispatch selected files in windows explorer to script see explorer_call.php source

The explorer action

This action type is special in the config: the value key in the config.ini for it is not used, so you don't need to define it.

Example use: If you assign it under hotkey Ctrl+Alt+6 as I did in the example, you can use this hotkey whenever a (Windows file) explorer is active/has focus (explorer.exe). If you trigger the hotkey it fetches the selected files and writes them to selected_files.txt in the program installation directory. As long as this file exists, the hotkey won't trigger again! It will then immediately call the explorer_call.php PHP-script, also in the installation directory, that can be defined to do whatever you want on this list of files. As long as it removes the selected_files.txt afterwards.

Contents of the default explorer_call.php script:

<?php
$files = explode("\n", trim(file_get_contents('selected_files.txt')));
unlink('selected_files.txt');

print_r($files);

system("pause");
?>

Small troubleshoot

If you crash the script, and selected_files.txt is not deleted, your shortcut key won't appear to work anymore, as the existance of this file also serves as a lock. Only when the file was processed and deleted can the explorer hotkey fire and launch the PHP script again. So when your hotkey appears non-responsive, chances are you need to delete selected_files.txt, or make the script more advanced img1.

Download

Download setup file: sanitizer-1.0-setup.exe.

The executable is compiled with VS2012 with platform target "Visual Studio 2012 - Windows XP (v110_xp)". VS2012 x86 redistributable is included in the setup. After install make sure to edit config.ini first, and realize that there is no GUI, the executable will run in the background. If you want to restart it use the restart_sanitizer.bat. If you want to kill it, use taskmgr or taskkill /IM sanitizer.exe.

Verify

If you start it with the sample config: Ctrl+Alt+4 should yield SomeOtherPassword in your clipboard; Ctrl+Alt+6 should print selected files in Windows explorer (do this from within explorer); Ctrl+Alt+1 should start putty.exe if you have that installed (and available in your PATH).

Windows 8 (Vista?) Disable UAC

If your system complains about not being able to write to selected_files.txt, just make it run as Administrator:

Explorer call use case: Tweakers.net foto uploader script

Update 10 jun 2013:

It's included in the installer in the example directory after install, an explorer_call.php script that makes it possible to upload images to your Tnet foto-album. Wrote a blog-post about it in Dutch here: http://cppse.tweakblogs.net/blog/9047/tweakers-fotoalbum-images-uploader.html.

Update 20 oct 2013:

Made a few changes to the tweakers script again, another Tweakers user wrote a blog about this: http://perkouw.tweakblogs.net/blog/9474/t-punt-net-fotoalbum-script!.html.

  • Now the only thing you need to edit is the TnetID (session id).
  • It will fetch the available foto albums itself.
  • I've also improved the check whether a file upload succeeded, it fetches the last known image from the fotoalbum, before and after the upload, if they match, the upload failed.
  • A summary of the uploads is now opened after the last image upload, instead of opening an url every upload ;)

(I'll update the installer later to include this new explorer_call.php)

C++ Comments (0)


Leave a Reply

Comment may not be visible immediately, because I process everything manually.**

**) I plan to automate this.., but it's on my ToDo since for ever..


Author:
Ray Burgemeestre
february 23th, 1984

Topics:
C++, Linux, Webdev

Other interests:
Music, Art, Zen