Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need an AHK script which creates:

  • a folder in the currently open folder in Windows Explorer (under Windows 7),
  • whose name consists
    • the current date in the format (yyyy-mm-dd)
    • the text which is currently in the clipboard
  • the newly created folder must contain 3 subfolders, named "1", "2", and "3"

I'd like to copy a few words (e.g. Testing Testing Testing) from another application, go to a location on my harddisk (using Windows Explorer), activate the hotkey, and AHK will create for me a folder named:

2012-06-04 Testing Testing Testing

with subfolders "1", "2", and "3".

share|improve this question
    
What have you tried already? Where are you getting stuck during creation of the AHK script? Or are you just asking us to write it for you? –  techie007 Jun 4 '12 at 14:32
    
i'm a AHK beginner and this is too complex for me –  user1298431 Jun 4 '12 at 14:47
add comment

1 Answer

The script

#c::
    WinGetClass, WinClass, A
    if (WinClass = "CabinetWClass")
    {
        FormatTime, CurrentDate,, yy-MM-dd
        CustomText = %Clipboard%
        Clipboard = 
        SendPlay, !d^c
        ClipWait, 1
        If ErrorLevel
        {
            MsgBox, Could not read directory name.
            return
        }
        CurrentDir = %Clipboard%
        Clipboard = %CustomText%
        NewDir = %CurrentDir%\%CurrentDate% %CustomText%
        Run, cmd /c (md "%NewDir%" || pause) && md "%NewDir%\1" && md "%NewDir%\2" && md "%NewDir%\3"
    }
    else
        SendPlay, #c
return

How it works

  • #c:: ... return specifies a key combination (here: Win + C) and executes ... when hit.

  • WinGetClass, WinClass, A stores the currently active window's title in the variable WinClass.

  • if (WinClass = "CabinetWClass") { ... } check if WinClass is CabinetWClass (Windows Explorer's class).

    If so:, ... gets executed. Otherwise, SendPlay, #c emulates a normal Win + C stroke.

  • FormatTime, CurrentDate,, yy-MM-dd stores the current date (YY-MM-DD) in the variable CurrentDate.

  • Clipboard = clears the clipboard, so we can check when something gets copied to it.

  • CustomText = %Clipboard% copies the current clipboard content in the variable CustomText.

  • SendPlay, !d^c selects the address bar and copies its content to the clipboard.

  • ClipWait, 1 waits for up to one second for the clipboard to contain any data.

  • If ErrorLevel { ... } checks if the clipboard contains any data.

    If it doesn't, the script aborts.

  • CurrentDir = %Clipboard% copies the current clipboard content in the variable CurrentDir.

  • Clipboard = %CustomText% sets the clipboard back to its original value.

  • NewDir = %CurrentDir%\%CurrentDate% %CustomText% specifies the new directory's name.

  • Run, cmd /c ... executes the command ... and then exits.

    • (md "%NewDir%" || pause) tries to create %NewDir%. On failure, it pauses, so you can see the error message.

    • md "%NewDir%\1" && md "%NewDir%\2" && md "%NewDir%\3" creates the 3 subdirectories.

share|improve this answer
    
thank you for your help but i cannot make it work. i paste the script in a .ahk file but what i see when i execute it is a quick flash of a command window and nothing happens –  user1298431 Jun 4 '12 at 17:32
    
@quanto: I tested it, and it works on my machine. What's your OS's language? The key combination [Ctrl] + A (to select all text) may vary on non English versions. –  Dennis Jun 4 '12 at 17:37
    
If I execute the script once, the cmd window just flashes for a while and nothing happens. If I try again, then there's a message: A subdirectory or file blabla\2012-06-05 blabla already exists. Press any key to continue... Maybe the path is wrong. I use English in my OS. Ctrl+A works –  user1298431 Jun 5 '12 at 9:04
    
Troubleshooting: Does the first blabla match the directory you were browsing when hitting the hotkey? Do you have any programs monitoring the clipboard? What custom text did you copy to your clipboard? –  Dennis Jun 5 '12 at 16:25
    
The custom text in the clipboard is "blabla". The directory I'm browsing has a totally different name. I exited most of the background applications but i'm not sure if the others monitor the clipboard. –  user1298431 Jun 6 '12 at 12:42
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.