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.

My plan is to create an Autohotkey macro that saves the currently opened file in Notepad++ on my Desktop. I was able to make it open the "Save as" standard dialog box, but I don't know how I can make it go to the Desktop (Windows 7). I know the ClassNN of the combobox where you can select the folder, but when I send a 'D' for desktop keystroke it goes into one of my partitions rather than my Desktop.

A hack would be to send a click to the combobox that contains the main directories, then send 'up arrow' 50 times, then send a 'd', then {enter}, but this is not very elegant or stable I think.

Here is my current code:

#IfWinActive, ahk_class Notepad++
!F11::
    Send ^s
    WinWaitActive, Save As
    ;ControlSend, ComboBox1, {Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up}{Up} d, Save As
    ControlSend, Edit1, `%USERPROFILE`%\Desktop\%A_Hour% %A_Min% %A_Sec%, Save As
    ;ControlSend, Button2, {Space}, Save As 
Return
#IfWinActive

The following is are sample realizations that are contaminated still with SHIFT at random times:

%USERPROFILE%|DEsktop\02 27 40
5USERPROFILE%\desktop\02 30 25
share|improve this question
1  
You could also specify C:\Users\UserName\Desktop as the default open/save directory for Notepad++. –  Karan Mar 8 '13 at 20:07
add comment

1 Answer

up vote 1 down vote accepted

Why not just give it the filename: %USERPROFILE%\Desktop\abc.txt

CODE:

MyFileName=abc
Send, `%USERPROFILE`%\Desktop\%MyFileName%`.txt

You have to escape the % signs and the dot.

You are not the only one with this problem. I can replicate it as well and there are several questions and no reliable answers around random shifts in a ControlSend on various fora.

One way to circumvent this is to use ControlFocus. Not as nice as ControlSend because you can potentially loose focus, but at least more reliable.

Sending a string is slow, so you could store the string in ClipBoard and send ^v to speed things up.

#IfWinActive, ahk_class Notepad
!F11::
    Send ^s
    WinWaitActive, Save As
    MyFileName=`%USERPROFILE`%\Desktop\%A_Hour% %A_Min% %A_Sec%
    ControlFocus, Edit1
    Send, %MyFileName%
    ;ControlSend, Button2, {Space}, Save As 
Return
#IfWinActive

OK, this is hopefully the last suggestion! This works flawlessly on my machine!

#IfWinActive, ahk_class Notepad
!F11::
    Send ^s
    WinWaitActive, Save As
        ControlSetText, Edit1, `%USERPROFILE`%\Desktop\%A_Hour% %A_Min% %A_Sec%, Save As
Return
#IfWinActive
share|improve this answer
    
i didnt know you could put an entire directory string in the filename. thanks again –  Wuschelbeutel Kartoffelhuhn Mar 8 '13 at 7:08
    
Actually, something odd is happening: The ControlSends are contaminated with keys that are SHIFT'ed. It appears SHIFT is active at random times, although it is not triggering the macro in any way (I also don't send any shift in the script itself): C:\uSers\, c:|USers\, C:|users, c:|uSers, c:|uSers\ c:\USers ....(in the US keyboard \ and | are the same key but the latter is activated with SHIFT). Any ideas what could be causing this? –  Wuschelbeutel Kartoffelhuhn Mar 8 '13 at 7:20
    
Check out my new code. Hope this solves your problem. –  Robert Ilbrink Mar 8 '13 at 7:25
    
thanks for the suggestion but it did not resolve the shift-issue. i have added sample output and my script in the original post. –  Wuschelbeutel Kartoffelhuhn Mar 8 '13 at 7:29
    
@Wuschelbeutel, Check out the modified code and let me know if this works better. –  Robert Ilbrink Mar 8 '13 at 8:00
show 2 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.