« Are you using 1010music Blackbox? The Blackbox Buddy can be of help when you reorganize the content on the microSD-card | Main| How to create a filter working with USB devices in Retrokits RK-006 »

Quickly simplify the path names within sound packs with AutoHotKey

Tags: 1010music Blackbox AutoHotKey
0

Why would I do that?

Because my 1010music Blackbox can show limited number of characters when I select sounds and neither does it scroll long file names. The long-file-name-scrolling has however been wished for in the 1010music’s Blackbox Forum here. Until then …

Take for example the following sound pack “Alex Stein – Rise Techno” which I have purchased from Loopcloud. When you dive into the directory structure, it looks like this:

image

I have highlighted all the “XOU_” prefixes, which most directories and files starts with. By removing this prefix, I shorten the directory and file name, giving more room for the Blackbox to show the interesting part of the directory- and file name!

You can of course change the directory names manually. The manual process is:

  • Press F2 in Windows Explorer. You can now change the directory name as you want
    image
    Note that the whole, old, directory name is selected. This makes it easy to completely remove and replace if that is what you want. However, you probably just want to remove “XOU_” …
  • Press the Home key to position the cursor at the start of the editable file name.
    image
  • Press the Delete-key 4 times to remove the “XOU_”-prefix. If the prefix is longer, you have to repeat more! 
  • Finally you have to press ENTER to save the changes.

Obviously this quickly become both tedious and error-prone.

Read on to see how I use a small AutoHotKey-script to create a global shortcut key like CTRL +  1 to remove the first part of the nane, the “XOU_”-part.

AutoHotKey is a very capable script processor, allowing you to do all sorts of things. It is pretty easy to create a script that can react to a global shortcut key press, and do stuff whenever that occurs. The processor works with script files with the file extension “.ahk”, and the ahk-files can be edited in any text editor, such as Notepad. If you want to have some more features related to the AutoHotKey itself, you can download and use the free Adventure IDE, which itself is an AutoHotKey-script! Yes, it is a wonderful example of advanced AutoHotKey-scripting showing you how to create a full Windows application too!

Below I have entered the following code into Adventure – and by the way – all the code is available to download here too, so you don’t have to type anything:

^1::
     MsgBox, Hey, you just pressed CTRL + 1
return

image

The code define a global short cut key with the first line: ^1::

The “hat” + 1, defines that AutoHotKey should react when the CTRL-key is pressed together with the “1”-key. There are other ways to define other keys if needed. If you for example want to use CTRL + SHIFT + 1 instead, the code would look like this: ^+1::

Whatever following the two colons will then be executed. On line 2 we simply pops up a message box indicating that you have pressed CTRL + 1. The final return-statement ensures that the code stops the CTRL + 1-processing here, and don’t continue to do potentially more stuff that intended.

If you press the Execute-button, as pointed out by the red arrow in screen shot above, the AutoHotKey-script will start. You won’t see anything but a little Tray icon representing the running AutoHotkey-instance. Now try to press CTRL + 1 …

image

The code works! You can try to switch to any other application in Windows. The CTRL + 1 key-combination will work anywhere, hence a global shortcut key.

We will of course extend our script a little to do what we want. That is to quickly remove 1, 2, 3 or even 4 parts of a file name according to what we see. Simply by pressing CTRL + n! This makes it much faster to correct directory names typically found in sound packs.

Below I have extended the script a little, so give you the main concept.

^1::
    LoopsAndSamplesNameCleaner(1)
return

^2::
    LoopsAndSamplesNameCleaner(2)
return

^3::
    LoopsAndSamplesNameCleaner(3)
return

^4::
    LoopsAndSamplesNameCleaner(4)
return

From what you have already seen, I have obviously added code for four shortcuts, CTRL + 1, CTRL + 2, CTRL + 3 and CTRL + 4. I obviously call some other code called LoopsAndSamplesNameCleaner, and more on that soon!

The idea is that you quickly determine how many words you want to remove from the directory name. Up until now, we have only had to remove one word, the “XOU_”-prefix. What if the folders were named like this?

image

In the screen shot above, you quickly see that you need to remove 3 words to get to the informative part of the directory name. Hence you should press CTRL + 3 in the example above.

Back to the LoopsAndSamplesNameCleaner-part. This is an AutoHotKey-function soon to be added to the script.

When I first created this script, I had success with the following version of the function – but note that this was due to the fact that I use Directory Opus as my Windows Explorer! Directory Opus obviously has more powerful control over how it can select word-parts from the file name. Anyway, I show you the code below for comparison:

image

The code above expect you to work with Explorer and have selected the first line you want to change. This is by the way, the default behavior of both Windows Explorer and Directory Opus.

image

If I press CTRL + 3 now, the LoopsAndSamplesNameCleanerDOpus-code will first press F2, sleep a little, then press Home, sleep a little, at then press CTRL + numWords (3 in our current case), sleep a little, then press Delete, sleep a little and then press the Down-arrow. As you see, the code mimics 100% the manual steps that you would do if you have no AutoHotKey.

What to do if you don’t use Directory Opus? Fare not – I have extended the code to also work with regular Windows Explorer. It is however, a little bit more code … My current LoopsAndSamplesNameCleaner-code looks like this;

image

The code looks somewhat similar. You might notice that this code uses the SendEvent-function instead of the previous Send-function. Besides being regarded as somewhat more stable, as seen here, it also pays attention to the SetKeyDelay-function preceding all the SendEvents.

The code-lines marked with 1, is the code that press F2, select all the content, and then press CTRL + C to put the content in the directory name onto the clipboard.

The code-line marked with 2, calls another function named RemoveWordsFromString. As you probably can guess from the function name, that function will remove the numWords from the string that comes from the clipboard.

Finally, the code-lines marked with 3 sets the changed content back onto the clipboard, and then instructs the directory-name in Windows Explorer to paste it in. The final line press TAB to navigate to the next directory name. Below you see the RemoveWordsFromString-function:

image

I won’t go into details in the function above, but the essence is that I’ll split the incoming directory name (passed into the function as the content-parameter) into its separate words. Then I simply rebuild the string dropping the number of words specified by the incoming parameter numWords.

All this together works fine as long as you work in Windows Explorer. The shown code can of course be robustified to it first check that you actually are working in Windows Explorer, and that you have at least one directory name to check. Robustification also involves error checking and whatnot. That can be an exercise for the readers.

What to do if anything goes wrong? In Windows Explorer you can revert the name changes one by one by clicking CTRL + Z (=undo!). Thus you should be pretty safe too.

Good luck renaming you sound packs – and happy playing with the Blackbox!

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)