AutoHotkey - persistent keystroke expansion? - HotStrings - windows

I am having trouble understanding how this product works. In the old days of Windows 3.1 and 95 I used these things called "hotkeys" where, no matter where I was in Windows, I could hit a certain key combination and it would happen. I assumed that was what this program did. Is it really just a scripting language?
I followed the "quick start" tutorial in the help file and it talks about creating a script and how to set strings for keystroke patterns to expand into. However, I created this simple script and put it in an AHK file on my Desktop:
::gsell::
Great Seller! A++++++++++++++++++++++++++++++++
Return
When I run the script from my desktop it appears to complete pretty much instantly, and of course it does nothing because I am on my desktop. I assumed there was some way to actually use these hotkeys in other applications, but it is not obvious to me and I've made a fair effort. Is this just an automation scripting language, or is there some simple way to set up some simple hotkeys and have them persist across applications?

Hotkeys and Hotstrings are available globally by default. Your issue with the expansion is likely because you have special characters that need to be escaped. Try the following:
::gsell::Great Seller{!} A{+}
; Simple Hotkey - Ctrl+F1
^F1::Msgbox, You pressed a hotkey

I decided to try an example from the help file and it did work. Apparently the place where I thought it was telling me the script was closed, was actually saying the script was still running, and it counts the number of seconds when you refresh. For some reason the text expansion is still not working, but this question is pretty much solved.

Related

Remap keys in OS X

Specifically I'm attempting to map my MacBook's fn key to left mouse click.
Back in the old days when I was using Windows, I came across a wonderful little utility that let me map anything to anything: http://www.autohotkey.com/
You create a little text file, e.g.
^!s:: ; CTRL + ALT + s
Send Sincerely,{enter}John Smith ; sends keystrokes to active window
return
Creating a simple text file was infinitely better than any GUI based remapper.
I can look through it and see everything that is going on at a glance
I can customise every last detail
I can save / retrieve / post / share my scripts
Really, it's the one thing I really miss about Windows.
So my question is: How do I go about doing this in OS X? Every Google search leads to https://pqrs.org/macosx/keyremap4macbook/ and I dislike this package: it has an insanely cluttered GUI.
I would be very happy if I could do it in a shell script, or even compile code.
HotKeys on OS X
Even though AHK is seemingly absent on Mac, the functionality that AHK provides on Windows can likely be achieved in OS X. It could be a matter of coding your own solution, modifying something that's open-source, or using a combination of applications that will work together. I haven't tried all of the following, but might as well mention them as they might be worth checking out:
Open Source
IronAHK - .NET rewrite of AHK ported to OS X
AHK Forum Thread
Github Project
*the original project might be dead
CliClick - command-line application that will emulate mouse clicks
Github Project
Commercial
TextExpander - scriptable text completion / hotkey / macro app (supports AppleScript, Shell scripts)
Typinator - similar to TextExpander, although some features vary.
KeyMo - mostly for mapping keys exclusively to your mouse.
FastScripts - maps hotkeys/user-definable keyboard shortcuts to AppleScripts
*I use Text Expander and FastScripts together and can't live without them.
Rolling Your Own
It's fairly easy to create something with an AppleScript, or a shell script for just about anything imaginable in OS X. For example, I've seen CliClick used along with a custom AppleScript to achieve a certain functionality that it might not provide otherwise. To find an AHK replacement on Mac it'll probably be through trial and error, patience, and ultimately what ends up working best for you.
It is possible with a program called ControllerMate, instructions here. It is, however, a commercial software. I'm also interested in finding a free alternative.
Sikuli project looks promising. Not sure about your particular problem (e.g. Fn key remapping), but it's definitely a crossplatform alternative to AHK.
Another Open Source solution to this problem not mentioned in l'L'l's answer is Karabiner; I have been looking for a way to remap the key to the left of 1 to Esc for a while, and this worked perfectly. It even resolved an issue I was having where swapping Cmd and Alt using the built in OSX key remapping was breaking terminal Alt shortcuts! Highly recommend it.

Open an application in a space using applescripts

I am trying to create a script that will open an application in a specific "space". So let's say I am on space 1 working in the terminal and then I want to be able to open safari in space 4. Is there a way to do this?
I have done some searching and found only ways to set the system profile options. Maybe I should tell you my end goal in case what I am attempting is not possible.
I use a laptop and plugin in to multiple stations, home, office, and travel. I want to create different window layouts for each one. So I will need an apple script telling it to open applications in varios spaces and different dimensions. I hope this makes sense. Ask me for clarification if it doesn't thanks!
PS the answer doesn't necessarily have to be any applescript I just thought that would be the easiest way :)
Here's a list of applescript commands for Spaces. There's a couple things there that might help you.
It is possible to do some scripting of application Space preferences by using the scripting interface to the System Events.app. See the answer to a similar question here.
The easiest way I've found is via GUI scripting. Make sure the Spaces menu is active on the upper right of your computer. That lists the spaces by number. You can then just write a GUI script to select the menu item of the space you wish. That will switch to that space. Then do an activate Applescript to open the application there.
Let me know if you need sample code demonstrating this. I have some in Python + Appsscript that does this but I should be easily able to convert it back to Applescript proper if you need it.

General Question about a GUI to execute a batch file

I'm new to programming and have taken some classes in it so I'm not sure if this is possible. I want to use a COTS software called 010 Hex Editor and write a script for the program to automate a couple tasks. These tasks can be run from a batch file according to their documentation.
Then I want to instruct the user to eject the device and reinsert it to clear the cache. (This I want done just with a simple pop-up window.
Then I also want to format the device which I assume can be done in a batch file as it can be done through dos on Windows.
My question is, with these 3 steps, can I build a simple GUI that has a button that says, "Start" or something like that, then the pop up window comes up to eject and reinsert, and then another button to format, and another button to exit. I'm not really familiar with what language this could be done in, and how to do this as the C++/Java classes I've taken have been more about syntax and OOP. Thanks!
You can use the windows messenger service to put up an alert - but on newer windows (vista/7) it's a pain to set all the permissions to allow this.
There are lots of free utilities that will popup a dialog from the command line, with a given message and wait for a response.
They are generally called messagebox or msgbox - sorry can't recommend any in particular

Taking notes to a background text editor without switching windows

I am looking for a solution to a specific use case:
When I read something on my browser or pdf reader, I want to take notes without switching windows. I want to type right on my browser or pdf reader, but the typed text should go to the background text editor like notepad.
Is this possible?
Do you know any existing automation script that handles this use case?
You should create an application that uses some keylogger-like techniques (e.g. global hooks) to monitor the keypresses and, depending on some condition (a setting you may have set, the currenctly active window, ...), it may pass them normally to the application or suppress them to store them in a buffer. Such buffer, then, would be shown to the user as needed.
Still, in my opinion a much more convenient way to perform a similar task would be to create an application consisting of a semitransparent edit box, that could be shown and hide simply with a hotkey. This would avoid all the hooks stuff and the potential problems that may arise from them.
you might try using autohotkey scripting language... I can write a little script that would do exactly what you need and afaik in this particular case it wouldnt need keyboard hooks.
--EDIT--
Autohotkey is VERY simple to use/learn so even if you want to do the script yourself you can do it in a very short time even if you dont have any knowledge of ahk. Then again, I can help you with it.

Which programming language is most fit for implementing a windows form dialog?

And how?
I want to implement an simple enough dialog with several buttons.
vb.net or c#.net both use .net framework. You can create a windows forms project that has rich user interface for buttons,forms,labels,grids... it is also very simple to start with using visual studio beucase visual studio has options to write parts of the code for you.
One of the easiest ways to get some simple dialogs and a bit of associated code running in Windows is AutoHotKey. It's free-as-in-beer, too.
It's a macro script environment where you can write little programs as scripts (and hook them to keys, that's where it got its name and original purpose).
AHK is a BASIC-like tiny scripting language that's all about simplicity and ease of use. Good enough for most small projects you'd care to do.
One use case/experience
I'm not a Windows programmer at all; I used to program in Delphi a bit, but now I'm mostly working in Java. Recently my girlfriend needed a bit of hacking: She bought a product with a registration key, and part of that key was smudged off the sticker. What we needed was a program to brute-force try all the possible missing letters/numbers in the program's registration dialog. Legitimate hacking, if you will.
I considered doing this in Delphi, then I started thinking about which arcane system calls I'd be needing to reach into the GUI of another program and to poke text into the input dialog... it turned out to be very easy in AHK. I needed about 10 minutes to write my hacking program, and it took about 5 minutes to find the right key.
If I remember correctly, my little program even included a dialog for specifying what we knew of the key, and which places had to be trial-and-errored. And of course a "start" button.
Update with example
I really wish I still had that little script I wrote as described above, but it's been several years and I've thrown it away.
I dug up this little gem on the net:
This is a working example script that uses a timer to change the names of the buttons in a MsgBox dialog. Although the button names are changed, the IfMsgBox command still requires that the buttons be referred to by their original names.
#SingleInstance
SetTimer, ChangeButtonNames, 50
MsgBox, 4, Add or Delete, Choose a button:
IfMsgBox, YES
MsgBox, You chose Add.
else
MsgBox, You chose Delete.
return
ChangeButtonNames:
IfWinNotExist, Add or Delete
return ; Keep waiting.
SetTimer, ChangeButtonNames, off
WinActivate
ControlSetText, Button1, &Add
ControlSetText, Button2, &Delete
return
I agree that this is a silly and useless program; I found it quite hard to find useful small examples on the 'net. Most of the people who write AHK scripts seem to enjoy hanging bells and whistles off their creations until they end up being full-fledged applications and no longer suitable as small examples.
A lot of useful snippets of code, though, can be found in AHK's Tutorial and overview:
http://www.autohotkey.com/docs/Tutorial.htm
Much of what they talk about is hanging certain capabilities off certain keys. This is how AHK started, but meanwhile it's a (mostly) full-fledged Windows programming language. So don't pay too much attention to the key mapping stuff.
Here's a cute little script to run Notepad and then issue a message box:
RunWait Notepad
MsgBox The user has finished (Notepad has been closed).
Here's a small dialog to get some input from a user:
MsgBox, 4, , Would you like to continue?
IfMsgBox, No
return
; Otherwise, the user picked yes.
MsgBox You pressed YES.

Resources