Jump to content


Photo

My scripts: simple, but useful


  • Please log in to reply
12 replies to this topic

#1 ibbignerd

ibbignerd
  • Members
  • 37 posts

Posted 23 July 2012 - 03:54 PM

Here are a couple scripts that I wrote. Most of them are pretty simple, but are really useful.

In Notepad++, WIN + S will save the current .AHK or .INI file and reload it with AutoHotkey. No more needing to right click on the tray icon. Also works really well for AHK scripts that use #NoTrayIcon.
#s::
If WinActive("ahk_class Notepad++")
{
    Send, ^s
    WinGetTitle, path,A
    StringReplace, path,path,- Notepad++
    StringReplace, path,path,*,
    Progress, B1 zh0 fs11 CWC0C0C0 WS900 W600 H28, Reloading: "%path%"
    Sleep,500
    path = "%path%"
    Run, AutoHotkey.exe /restart %path%
    Progress, Off
}
return
Use just the mouse to switch between windows. Middle button click will result in an ALT + TAB function. holding down right click and scrolling the wheel up and down will switch between tasks. When the right click is released is when it actually switches to that task.
Mbutton::
Send, !{TAB}
return

Rbutton::Mouseclick, Right ;need this or right click won't work
Rbutton & WheelUp::AltTab
Rbutton & WheelDown::ShiftAltTab
Scroll between tabs in chrome when the mouse is in the bookmark bar or higher. The variables here are the window selector and the ychrome checker. These can be changed based on which browser you are using and personal settings.
~WheelDown::
if winactive("ahk_class Chrome_WidgetWin_1")
{
MouseGetPos, xchrome, ychrome
if (ychrome < 92)
{
Send, ^+{Tab}
}
}
Return

~WheelUp::
if winactive("ahk_class Chrome_WidgetWin_1")
{
MouseGetPos, xchrome, ychrome
if (ychrome < 92)
{
Send, ^{Tab}
}
}
Return
Use ALT + Wheel to adjust the sound. Middle button toggles the mute function.
!WheelUp::Send, {Volume_Up}{Volume_Up}
!WheelDown::Send, {Volume_Down}{Volume_Down}
!Mbutton::Send, {Volume_Mute}
The PrintScreen button auto opens Paint and pastes it into the canvas. (it also saves your current clipboard)
PrintScreen::
clipsave = %clipboard%
Send, #{PRINTSCREEN}
Run, mspaint.exe
WinWaitActive ahk_class MSPaintApp
{
Send, ^v
}
clipboard = %clipsave%
return
Sets the current window to 35 transparency when you do CTRL + SPACE. This lets you view the windows behind the current without switching windows.
^Space::WinSet, Transparent, 35 , A
^Space UP::WinSet, Transparent, OFF, A
return
WIN + 2 will check to see if a Chrome window is running, if it is, it will activate and maximize, if not, it will run Chrome.
#2::
if WinExist("ahk_class Chrome_WidgetWin_1")
{
	WinActivate
	WinMaximize
}
else
    Run Chrome.exe
return
If you have any questions about my code or how it can work for you, just let me know. Thanks!

#2 ibbignerd

ibbignerd
  • Members
  • 37 posts

Posted 23 July 2012 - 05:04 PM

Here's another one that's pretty useful. It will toggle the KeyHistory window on WIN + C

#c::
if winexist("C:\Program Files (x86)\AutoHotkey\AutoHotkey.ini - AutoHotkey v1.0.48.05")
{
winActivate
send, !{F4}
}
else 
{
#InstallKeybdHook
KeyHistory
}


#3 Carrozza

Carrozza
  • Members
  • 199 posts

Posted 25 July 2012 - 01:00 PM

Interesting ideas.
The Printscreen one is going to be inserted in my "general" script immediately, but also others are worth some time to be evaluated.
Cheers!

#4 klownboy

klownboy
  • Members
  • 77 posts

Posted 25 July 2012 - 10:09 PM

Hi ibbignerd,
Great scripts...some of the nicest ones are the simplest.
I'm new to AHK, but I played with the save and reload script since it seemed very usefull being that I'm doing that constantly. I stumbled across the "reload" command and used that instead of restart. It seems to work just fine. I tested it numerous times but using TextPad. When using the "reload" command you don't even have to get the path/filename provided I suppose you're working exclusively on AHK files (which is what I've been doing). I left the finding path code lines in there strictly so I could show the path in the "Progress" command (i.e., they're not needed for the reload command).

#s::
If WinActive("ahk_class TextPad4")
{
Send, ^s
WinGetTitle, path,A
StringReplace, path,path,*,
StringReplace, path,path,TextPad -
Progress, B1 zh0 fs11 CWC0C0C0 WS900 W600 H28, Saving and reloading: "%path%"
Sleep,2000
reload
Progress, Off
}
return

Thanks again for the scripts...keep em coming!
Ken

#5 Guests

  • Guests

Posted 26 July 2012 - 06:22 PM

Instead of
#s::

If WinActive("ahk_class TextPad4")
I'd recommend
#IfWinActive, ahk_class TextPad4

#s::
Note the # before IfWinActive there is a huge difference ;-)

#6 skoliver1

skoliver1
  • Members
  • 32 posts

Posted 27 July 2012 - 11:13 AM

This is one I picked up elsewhere that seems simpler that the one above.

This will save and reload the script you are working on in any editor, Notepad, Notepad++, etc.

$^s::
SetTitleMatchMode RegEx
IfWinActive, %A_ScriptName%
{
   Send, ^s
   SplashTextOn,,,Updated script,
   Sleep,1000
   SplashTextOff
   Reload
}
else
   Send, ^s
return


#7 vahju

vahju
  • Members
  • 327 posts

Posted 27 July 2012 - 02:19 PM

I use the script below for saving ahk files and it seems to work great. Doesn't have a splash screen or tooltip but that is fine with me.

;reload script when saving - http://www.autohotkey.com/community/viewtopic.php?p=545699#p545699
~^s::
    WinGetActiveTitle, Reload
    If InStr(Reload, ".ahk")
       Reload  ;The only thing you need here is the Reload
Return


#8 JamixZol

JamixZol
  • Members
  • 54 posts

Posted 28 July 2012 - 05:59 AM

my favorite part of my startup script:
:*:-_-::{U+0CA0}_{U+0CA0}
turns -_- into
Redit face ಠ_ಠ

#9 ibbignerd

ibbignerd
  • Members
  • 37 posts

Posted 28 July 2012 - 07:17 AM

I stumbled across the "reload" command and used that instead of restart.


That only reloads the current program. The way I'm doing it, it reloads the file whether it's a .ahk or .ini file.

#10 ErrorOnLine1

ErrorOnLine1
  • Guests

Posted 28 July 2012 - 01:23 PM

Re: PrintScreen

I use PrintScreen quite often, so thanks for this, ibbignerd. I swapped out mspaint for IrfanView.

Run, %A_ProgramFiles%\IrfanView\i_view32.exe , , max
WinWaitActive, IrfanView


#11 ibbignerd

ibbignerd
  • Members
  • 37 posts

Posted 07 August 2012 - 03:42 PM

I recently expanded my save script to work with Sublime Text 2 as well as Notepad++ to be a little more intuitive. If you have an editor that you use and want this save function, let me know and I will make a save for it. Here it is:

~^s::
If WinActive("ahk_class PX_WINDOW_CLASS") ;Sublime Text 2
{
    sleep, 200
    ifWinExist, ahk_class #32770 ;Window that says that Sublime isn't registered
    {
        winclose
        Progress, B2 zh0 fs11 CW000080 CTFFFFFF WS900 W600 H28, Box has been closed
        sleep, 400
        progress, off
    }
    WinGetTitle, path,A
    StringReplace, path,path, - Sublime Text 2 (UNREGISTERED)
	StringReplace, path,path, (X)
    Progress, B2 zh0 fs11 CW000080 CTFFFFFF WS900 W150 H28, ...
    ifWinExist, ahk_class #32770
    {
        winclose
        Progress, B2 zh0 fs11 CW000080 CTFFFFFF WS900 W600 H28, Box has been closed
        sleep, 400
        progress, off
    }
    Sleep, 500
	ahk = .ahk
	IfInString, path, %ahk%
	{
    path = "%path%"
    Run, AutoHotkey.exe /restart %path%
	}
	ini = .ini
	IfInString, path, %ini%
	{
    path = "%path%"
    Run, AutoHotkey.exe /restart %path%
	}
    Progress, Off
}
If WinActive("ahk_class Notepad++")
{
    sleep, 20
    WinGetTitle, path,A
    StringReplace, path,path, - Notepad++
	StringReplace, path,path,*
    Progress, B2 zh0 fs11 CW000080 CTFFFFFF WS900 W100 H28, Reloading...
    ifWinExist, ahk_class #32770
    Sleep,500
	ahk = .ahk
	IfInString, path, %ahk%
	{
    path = "%path%"
    Run, AutoHotkey.exe /restart %path%
	}
	ini = .ini
	IfInString, path, %ini%
	{
    path = "%path%"
    Run, AutoHotkey.exe /restart %path%
	}
    Progress, Off
}
return


#12 hemantsurve

hemantsurve
  • Members
  • 1 posts

Posted 09 August 2012 - 07:36 AM

Nice Scripts you have ibbignerd ....:)

#13 ibbignerd

ibbignerd
  • Members
  • 37 posts

Posted 09 August 2012 - 01:16 PM

Nice Scripts you have ibbignerd ....:)

Thank you