Tuesday, February 5, 2013

My current base AutoHotKey script


Posting my latest AutoHotKey base script - the one I have set to load on system startup. You can run multiple scripts concurrently simply by double-clicking them, and I have a number of scripts I run for specific purposes, while I'm developing, doing graphics work, etc., but this is the one I have running all the time.

If you have AutoHotKey installed and want to try this script out, download it and double-click to run it. Most of the snippets inside have been snagged from other scripts, attributions with links are included inline.

Currently it supports the following features:

Hotkeys

You'll need to have the associated programs installed, obviously. You can update your paths in the script as necessary.

  • Pressing Ctrl/Win/Alt + P opens a new Notepad window.
  • Pressing Ctrl/Win/Alt + N opens Notepad++ (or switches to it if it's already running).
  • Pressing Ctrl/Win/Alt + S opens Sublime Text 2.
  • Pressing Ctrl/Win/Alt + C opens ConEmu.


Change text case

  • Pressing Ctrl/Win/Alt + U converts the selected text to uppercase.
  • Pressing Ctrl/Win/Alt + L converts the selected text to lowercase.
  • Pressing Ctrl/Win/Alt + K capitalizes the selected text.

Hotstrings

  • Pressing ]d followed by one of the standard character endings - a space, period, tab, etc. spits out a date/time stamp.

Window transparency

I find this useful for many situations, but especially when I'm doing layout work and want a pixel-perfect match to the design.
  • Holding Win/Alt and then either hitting the Up arrow key or scrolling up with the mouse wheel increases the transparency of the active window.
  • Holding Win/Alt and then either hitting the Down arrow key or scrolling down with the mouse wheel decreases the transparency of the active window.
  • Holding Win/Alt and tapping G displays a tooltip with current transparency value of the window under the mouse pointer.
  • Holding Win/Alt and either clicking anywhere with the left mouse button or tapping the left arrow key turns the window completely opaque.
  • Holding Win/Alt and either clicking anywhere with the right mouse button or tapping the right arrow key turns the window almost completely transparent..


Window always on top

  • Holding Win/Alt and tapping T sets the active window to Always on Top.


Window drag

This is basically the Linux feature where you can drag a window around by clicking anywhere in it, instead of having to click the title bar. I rarely use this, especially with the existing controls in Windows, as well as the new ones added with Windows 8, but it comes in handy occasionally.
  • Clicking anywhere in a window while holding down the right Alt key moves the window around with the mouse.

Volume

  • Pressing Ctrl/Win/Alt and then either tapping the Up arrow key or scrolling up with the mouse wheel increases the volume in increments of 2.
  • Pressing Ctrl/Win/Alt and then either tapping the Down arrow key or scrolling down with the mouse wheel decreases the volume in increments of 2.
  • Pressing Ctrl/Win/Alt and then hitting the Left arrow key mutes the volume.
  • Scrolling with the mouse over the taskbar increases/decreases the volume (no keyboard interaction necessary for this).

The script

You can download the script here (base.ahk), and I've posted it for quick viewing below (you can also just copy/paste the following locally and give it a .ahk extension).



; MY BASE FILE
; @threecleartones
; ==========================================================================

; NOTES
; ==========================================================================
; http://www.autohotkey.com/docs/KeyList.htm
; http://www.autohotkey.com/docs/Hotkeys.htm
; + is SHIFT
; ^ is CTRL
; # is WINDOWS
; ! is ALT


; HOTKEYS
; ==========================================================================
$Pause:: Suspend  ; Suspend/unsuspend AutoHotKey, just in case I need to.
^#!p:: Run Notepad  ; Open a new Notepad window
^#!n:: Run Notepad++  ; Open Notepad++
^#!s:: Run "C:\Program Files\Sublime Text 2\sublime_text.exe"  ; Open Sublime
^#!c:: Run "C:\Program Files\ConEmu\ConEmu64.exe"  ; Open ConEmu

; Change text case
; Snagged from http://webserver.computoredge.com/online.mvc?issue=3029&article=vista
^#!u::                             ; convert text to upper
 Clipboard:= ""
 Send, ^c ;copies selected text
 ClipWait
 StringUpper Clipboard, Clipboard
 Send %Clipboard%
return

^#!l::                            ; convert text to lower
 Clipboard:= ""
 Send, ^c ;copies selected text
 ClipWait
 StringLower Clipboard, Clipboard
 Send %Clipboard%
return

^#!k::                           ; convert text to capitalized
 Clipboard:= ""
 Send, ^c ;copies selected text
 ClipWait
 StringUpper Clipboard, Clipboard, T
 Send %Clipboard%


; HOTSTRINGS
; ==========================================================================
::]d::  ; This hotstring replaces "]d" with the current date and time via the commands below.
; FormatTime, CurrentDateTime,, yyyy.M.d h:mm tt
FormatTime, CurrentDateTime,, yyyy.M.d H:mm
SendInput %CurrentDateTime%
return


; WINDOW TRANSPARENCY
; ==========================================================================
; Snagged from http://www.howtogeek.com/howto/44915/how-to-change-window-transparency-in-windows-7/
#!WheelUp::  ; Increments transparency up by 3.375% (with wrap-around)
#!Up::
    DetectHiddenWindows, on
    WinGet, curtrans, Transparent, A
    if ! curtrans
        curtrans = 255
    newtrans := curtrans + 8
    if newtrans > 0
    {
        WinSet, Transparent, %newtrans%, A
    }
    else
    {
        WinSet, Transparent, OFF, A
        WinSet, Transparent, 255, A
    }
return

#!WheelDown::  ; Increments transparency down by 3.375% (with wrap-around)
#!Down::
    DetectHiddenWindows, on
    WinGet, curtrans, Transparent, A
    if ! curtrans
        curtrans = 255
    newtrans := curtrans - 8
    if newtrans > 0
    {
        WinSet, Transparent, %newtrans%, A
    }
    ;else
    ;{
    ;    WinSet, Transparent, 255, A
    ;    WinSet, Transparent, OFF, A
    ;}
return

#!LButton::  ; Make the window 100% opaque - reset Transparency Settings
#!LEFT::
    WinSet, Transparent, 255, A
    WinSet, Transparent, OFF, A
return

#!RButton::  ; Make the window 80% transparent
#!RIGHT::
    WinSet, Transparent, 20, A
return

#!g::  ; Press Win+G to show the current settings of the window under the mouse.
    MouseGetPos,,, MouseWin
    WinGet, Transparent, Transparent, ahk_id %MouseWin%
    ToolTip Translucency:`t%Transparent%`n
Sleep 2000
ToolTip
return


; WINDOW ALWAYS ON TOP
; ==========================================================================
; Snagged from http://www.howtogeek.com/howto/13784/keep-a-window-on-top-with-a-handy-autohotkey-script/
#!t::  Winset, Alwaysontop, , A


; WINDOW DRAG
; ==========================================================================
; Snagged from http://www.howtogeek.com/howto/windows-vista/get-the-linux-altwindow-drag-functionality-in-windows/
; This script modified from the original: http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm
; by The How-To Geek
; http://www.howtogeek.com 

RAlt & LButton::
CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin% 
if EWD_WinState = 0  ; Only if the window isn't maximized 
    SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return

EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U  ; Button has been released, so drag is complete.
{
    SetTimer, EWD_WatchMouse, off
    return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D  ; Escape has been pressed, so drag is cancelled.
{
    SetTimer, EWD_WatchMouse, off
    WinMove, ahk_id %EWD_MouseWin%,, %EWD_OriginalPosX%, %EWD_OriginalPosY%
    return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY,,, ahk_id %EWD_MouseWin%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%,, EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX  ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return


; VOLUME
; ==========================================================================
; Adjusts the volume using a hotkey/mouse scroll combo
#!^Up::
#!^WheelUp::
Send {Volume_Up 2}
return
#!^Down::
#!^WheelDown::
Send {Volume_Down 2}
return
#!^Left::Send {Volume_Mute}

; Adjusts the volume when mouse scrolling over the taskbar (like volumouse)
; Snagged from http://l.autohotkey.net/docs/commands/_If.htm#Examples
#If MouseIsOver("ahk_class Shell_TrayWnd")
WheelUp::Send {Volume_Up}     ; Wheel over taskbar: increase/decrease volume.
WheelDown::Send {Volume_Down} ;


; MISC STUFF
; ==========================================================================
; Reload the script by middle clicking on the taskbar.
; This is useful when making changes to the script, but also necessary when the volume stuff further down stops working for some reason.
; Also, this has to be at the end of the file for some reason.
#If MouseIsOver("ahk_class Shell_TrayWnd")
MButton::Reload
MouseIsOver(WinTitle) {
    MouseGetPos,,, Win
    return WinExist(WinTitle . " ahk_id " . Win)
}
#SingleInstance force  ; Allows only one instance of this script to run.




Tuesday, September 18, 2012

Chocolatey, package manager for Windows

Installing WinMerge via Chocolatey, a Linux-style package manager for Windows. Well, it's not really a Linux-style package manager, especially since it won't automatically find dependencies, but for those who like the command line or just want to try a different way of installing Windows programs than actually visiting a website, downloading the program, and running the installer, this is quicker and fun. Perusing the list of programs in the database is educational as well for software junkies.

To save a list of the current database, type something like the following:

clist > c:\choco-list.txt

Found this via Lifehacker.

"Pin" a site in Windows 7/8 that opens in Google Chrome


I've been using IE10 in Windows 8 to surf Facebook.com for several months. It's always worked fine, but about a week ago it seems that Facebook introduced a change that IE10 can't handle - photo overlays (when you click on a photo in Facebook) are all broken in IE10. It's easy enough to open the site in Chrome, but I find myself missing the coolness of just clicking the big pinned Facebook icon sitting in my taskbar.

What's a "pinned site"?

For those not familiar with this, one of the features introduced in Windows 7, and continued in Windows 8, is the notion of "pinned sites". Open a site in IE9 or IE10 and drag/drop the site icon in the address bar onto the taskbar, and it will create an icon for that site on the the taskbar that will use the site's default favicon and will, when clicked, open the site in Internet Explorer. The browser's window color will be automatically themed to match the dominant color in the favicon (this is fun). If the site's developers have added the appropriate meta tags, there will be customized options available for the site in the icon's right-click menu. Facebook's pinned icon even displays an asterisk on the icon when there are new notifications!

How do I get a "pinned site" to open in Chrome?

After a bit of experimentation I figured out a way to put a "pinned" icon in the taskbar that, when clicked, opens facebook.com in Chrome, even if IE is set as your system's default browser:

- Open Chrome.
- Right-click the taskbar icon and pin it to the taskbar.
- Right-click the newly pinned icon, and at the bottom of the context menu, just above the "Unpin" option, right-click the Chrome icon and go to Properties.
- In the Target field, put your cursor at the end of the line, add a space (if there isn't one already), and type "facebook.com", without the quotes. (as a paremeter, basically).
- Go to the General tab and change the name of the shortcut to "Facebook", without the quotes.
- The icon will be Chrome's, if you have a Facebook image file you want to use for the icon, you can use the "Change icon" button to do it, although you may need to mess with the file some depending on the format.

Now you've got what appears to be a pinned site icon on the taskbar that opens facebook.com in Chrome instead of IE. Unfortunately, it's not a real pinned site - it won't have the extra right-click options like "News" or "Messages" that the actual pinned icon would have, and it won't change when there are new facebook notifications - but until either Microsoft or Facebook fixes whatever is causing photo overlays to break in IE10, this is the next best thing!

Wednesday, January 25, 2012

Synergy between PC and Mac

While spending another evening at home working on work, I finally decided I'd had enough of occasionally reaching for my desktop mouse while working on my MBP and the brief moment of confusion that follows when the PC mouse fails to move the Mac pointer, so I installed Synergy, which I last played with about five years ago. Setting it up on a Mac is a royal pain, so if you're interested in doing what I did - installing Synergy on a Windows 7 box and an MBP running Snow Leopard on the same local network so you can use one mouse/keyboard between the two of them (without extra hardware) - then follow these steps:

Step 1 - Download Synergy
Download the Synergy installer on each system: 


Step 2 - Install  Synergy on the Mac
On the Mac, double-click to unzip the archive and then navigate to the new directory in Terminal. Then move the two executables to /usr/bin:

sudo synergy* /usr/bin/

Go to /usr/bin/ in Terminal and change the permissions on the two files:

sudo chmod 755 synergyc
sudo chmod 755 synergys

Step 3 - Install  Synergy on the PC
Double-click the installer.

Step 4 - Download QSynergy
QSynergy is a cross-platform front-end for Synergy, download it on both systems:


Step 5 - Install  QSynergy on the Mac
Double-click the installer and command-tab over to the new Finder window. Open a new Finder window and navigate to the Applications folder. Drag the QSynergy.app icon into the Applications folder.

Step 6 - Install  QSynergy on the PC
Double-click the installer.

Step 7 - Configure QSynergy on the PC
Run QSynergy (tap Start, type the first few letters of QSynergy and hit Enter). Check "Use this computer to control others", click "Interactively configure synergy" and click the  "Configure Server" button.


A monitor icon for your Windows system should already be present in the center of the grid. Drag the monitor icon in the upper right down into the grid to add a screen for your Mac. Place it wherever you'd like the screen to exist "virtually", so that when you move your mouse to that edge of your Windows monitor the pointer moves into the Mac monitor.

Double-click the icon for the new screen you just added to configure it. All you need to do is add your Mac's WINS name to the "Screen name" field, followed by ".home". To check your WINS name on your Mac, go to Apple menu > System Preferences > Network > Click the active network connection > Click the "Advanced" button > Click the WINS tab > Look in the "NetBIOS Name" field.

Type the name in the "Screen name" field on your Windows box, followed by ".home", ex:

KERMIT.home

Click OK and you're done.

Step 8 - Configure QSynergy on the Mac
Run QSynergy (tap COMMAND + SPACE, type the first few letters of "QSynergy" into the Spotlight field in the upper right, make sure "QSynergy.app" is highlighted and hit Enter). Check "Control this computer from another one" and type the name of your Windows box into the "Name of the server" field. To check the name, tap Start on your Windows box, right-click "Computer", select Properties, and look at the value for "Computer name".

Type the name into the "Name of the server" field on your Mac.

Note: if you have trouble connecting later, try typing your Windows box's IP address into this field instead of the name.

Step 9 - Run the server on the PC
Click the "Start" button in the QSynergy window on your PC.

Step 10 - Run the client on the Mac
Click the "Start" button in the QSynergy window on your Mac.

Step 11 - Check that it works
If the Synergy system tray icon on the Windows box displays a little lightning bolt, the connection's been established. Try moving your Windows mouse pointer past the edge you chose during configuration on your Windows monitor. If you don't remember which edge you chose, try all four of them! If everything works, your Mac pointer should suddenly start moving with your PC mouse as soon as you've moved the Windows pointer past the chosen edge. You should be able to move it freely between the two monitors.

These steps "just worked" for me. If they don't work for you, try the QSynergy support page:

Monday, January 16, 2012

Put together a system for my five-year old...

She's learning about computers in kindergarten so I figured it's high time she became comfortable with one at home. Rebuilt an old HP Slimline I haven't used in like three years, a 17" Sony monitor collecting dust in the garage, and my backup wired Logitech laser mouse. For once I didn't have an extra keyboard lying around, so I gave her the standard issue Dell I use on my main desktop (always thought of myself as a tricked-out keyboard type of guy, but ever since my last wireless, ergonomic, multimedia enhanced keyboard died a couple years ago, the Dell has, surprisingly, been more than adequate). After a couple hours in Windows Update (I think the last time I turned this system on was in 2008 or 2009), the setup's running smoothly, and my kid's in seventh heaven. Also known as pbskids.org.

This of course left me with a mouse but no keyboard for my main system, until my next visit to Micro Center. I was able to log in using the mouse and the on-screen accessibility keyboard, but after logging in, using it for everyday tasks gets old quick. Luckily it didn't take long for me to remember Windows Speech Recognition, which I'd last played with in 2009 when Vista was released. Seems to work about the same in Windows 7 (I love it), but that's another post. A couple days later I was finally able to get over to Micro Center and peruse the keyboard aisle.

At first I thought I'd get another tricked out multimedia keyboard, but upon reflection, I decided to look at the small form factor bluetooth keyboards. What I'd love is a bluetooth, backlit keyboard with a numpad and a decent look for under $100 (or even $50), but that day hasn't come yet. What I walked out of the store with was a small, bluetooth keyboard by a company called "Rocksoul" for $30. It has chiclet keys and a nice simple look:



It wasn't until I got home and took it out of the box that I realized it was a Mac keyboard - instead of a Windows key, it had a Command key, which was flipped with the Alt key.

After going crazy trying to use it for a few minutes (never realized just how often I hit Alt+Space to bring up a window's system menu), I decided to remap the keys to my liking. I was surprised to find that Windows 7 doesn't really come with a way to do this (aside from manually editing the registry), although Microsoft's Keyboard Layout Creator is a free download. It sucks though, and I didn't feel like trying any others out once I discovered that a utility I already use, AutoHotKey, lets you remap keys as well.

Here's the code I entered into my AutoHotKey script to swap the Command and Alt keys:

; Keyboard remap
LWin::LAlt
RWin::RAlt
LAlt::LWin
RAlt::RWin


In the end, I think I've decided to return this keyboard after all. While I like the small form factor in principle, it's distracting to type on it, and I miss the extra keys like the numpad, Home/End/Delete, Page Up/Down, and the Print Screen key. Furthermore, there's no Control key on the right side, and the leftmost bottom key is not Control but a Function key, very distracting. Finally, and I think this is a Mac thing - the Escape key only works for some things. I can dismiss a select list with it, but can't, for example, dismiss an open dialog box, which is second nature to me.

All in all, a nice enough keyboard, but not for me.

Wednesday, January 4, 2012

Access your recently used apps with Dock4Droid

I find accessing recently used applications on my HTC Incredible (Gingerbread) to be slightly annoying, mostly because I'm a lazy, impatient, good for nothing bum. You just tap and hold the Home button for a second. The main issue I have with it is Android's faux multi-tasking, but that aside, the slight delay when holding the Home button trips me up when I'm on a roll or in a hurry, and I'm limited to eight recent apps. There are a number of solutions that help manage recent tasks. Today I found one that, while it doesn't actually speed me up, is a welcome change (for the moment).

"Dock4Droid" puts an OSX-style dock on your phone. It's minimized to a thin, transparent glowing bar on one edge of the screen. Tap and hold, and the dock pops up, complete with magnification, displaying icons for your most recently used apps. Pausing on an app icon and releasing launches the app. Dragging your finger off the dock, or past the end of the list, dismisses the dock (unlike OSX, where this action removes the icon from the dock).

The dock can be customized in a number of ways. I've only tested the free limited version, but the dock can be moved to any screen edge, number of recent apps set, colors changed, etc.

Give it a try, here's the Market link for Dock4Droid.