Starting AutoHotkey GUI min/max/hidden from OUTSIDE the script - user-interface

You can start Windows programs minimized/maximized/hidden from outside the program. For example, from the command-line with start /max notepad or by setting the Run field for a shortcut in its Properties dialog. AutoHotkey also supports starting programs min/max/hidden with the Run command.
But how can an AutoHotkey script/program that has a GUI support this?
Here's a simple sample script:
gui,add,edit,w100 h100
gui,+resize
gui,show
Running the script will show a resizable window just big enough for the edit-control.
Running the script with start /max or any other method does NOT start it maximized (it doesn't matter if the script is compiled or not, it's the same result).
(Yes, it's possible to manually maximize the window or do it from the script, but that's not the goal. The goal is to have the GUI default to some size, but allow users to override it, like with other Windows programs.)
Does AutoHotkey support nShowCmd in WinMain? There don't seem to be any A_ variables that contain it. đŸ€”
What's the solution?

My approach would be something like this:
gui,add,edit,w100 h100
gui,+resize
gui,show
if InStr( A_args[1], "max")
WinMaximize, A
if InStr( A_args[1], "min")
WinMinimize, A
if InStr( A_args[1], "hid")
WinHide, A
Then you can:
Start script.ahk "maximized"
Or
Start script.ahk "minimized"
Or
Start script.ahk "hidden"
The argument dont need to be complete, if it contains "max", "min" or "hid" in it, it will work

Related

Automatically switching between two running programs

Because I really don't know a lot about this domain of programming, it might be clearer for me to explain what I would do if I were to input myself the commands I want to automatize (i.e. I just launch a script and all this procedure should be done automatically).
Lauch both the Game and the Task.
Start a game of the Game and immediately pause it.
Alt tab to the task.
Do it until a point determined in the program. At which point I am
told to switch to the game.
Alt tab to the game
Unpause it and start a clockwatch.
When the clockwatch reaches X minutes (X determined in advance),
pause the game.
Alt tab to the task.
Repeat steps 4-7 N number of times.
I have no idea whether it is possible or what tools to use. I understood that a simple bash file won't be enough and I might need to use a "fake keyboard" program to force some inputs (such as "space bar" to pause the game). But I have no idea how to coordinate all of that.
Thanks in advance for any help. Even telling me it's not possible is an acceptable answer :)
EDIT : Edited the list for clarity
From what information you have given, it is difficult to tell whether the complete process can be automated, but there are tools like AutoHotKey which you can use to write scripts to automate desktop applications.
A simple script in autohotkey to start a program "Notepad", another program "Calculater", and switch back to "Notepad" and write "Hello World!" in it.
SetTitleMatchMode, 2
Run "C:\Windows:\Notepad.exe"
Run "calc.exe"
WinActivate, Notepad
Send, Hello World!
The above is a very simple script. It does not activate the specific notepad window you want if multiple notepad windows are open. However, that can be automated too.

In Visual Studio, find and commands by name?

I'd like to use the keyboard more in Visual Studio, and my memory for ctrl+alt+f??, alt+?? key combinations is failing me.
I'd prefer an adjunct like the emacs model, where it's possible to search commands by name; For instance, in emacs you type
alt+x enab <tab><tab>
and it presents you with a list of commands starting 'enab';
enable-command
enable-flow-control
enable-theme
I'd like to know if there is a shortcut or extension so that I could do something similar in VS, like
alt+x imm <tab><tab>
and then choose to execute one of
Debug.Immediate
Tools.ImmediateMode
Any clues?
EDIT
Both #Trillian and #the_mandrill have given me the right answers. It turns out there are two ways to enter the kind of mode I'm looking for;
1) The Edit.GoToFindCombo, which gives you a small bit of menu-bar space to type things like
>Debug.Immediate
2) The View.CommandWindow, which gives you a full panel (like the immediate window or the output window) which allows you to type in a bit more space and see the text output of executed commands.
It's also possible to alias commands in either window yourself, using the command window and a syntax like
alias sol View.SolutionExplorer
And to retrieve the current list like
alias
I've mapped Edit.GoToFindCombo to alt-x and View.CommandWindow to alt-shift-x and it's feelimg more emacs-y already :)
It would be nice if this was integrated in the Ctrl+Q Quick Launch box. Until then, the best built-in tool for this is probably the Go To Find Combo. You can use this to launch arbitrary commands by typing the '>' character and then the beginning of a Visual Studio command, including those you listed. You get autocompletion, but only for strings that start with what you're typing, so >Deb would list you all commands starting with Debug.. For your specific example, >imm would actually work because there is an immed shortcut to Debug.Immediate, but in general you'll have to know the prefix.
The Go To Find Combo is not in the VS2013 UI by default, but you can add it to any toolbar by selecting "Customize" and finding the command in the "Edit" category. Once it's sitting in a toolbar, the Ctrl+/ shortcut will give it the focus by default.
The '>' prefix for command completion also works from the Command and Immediate windows.
Try using the Command Window (Ctrl-Alt-A). This brings up an emacs-like command buffer. Type:
Deb.Imm<tab>
to expand to Debug.Immediate. Typing the '.' forces autocompletion if there's one unique command (Debug is the only match for 'De'). Tab key will cycle through options. More info at the Command Window article on MSDN. There's also a list of Aliases that you can also add your own to, eg
alias di Debug.Immediate
I've also just discovered that you can type Ctrl-\ to set the focus to the Find pane and enter a command directly in there.

Type a pre defined text when a shortcut key is pressed in Windows 7

I work on mainframes and don't have much knowledge about windows other than playing warcraft :-) hence pardon me if I ask something nooby/silly.
I have a requirement to enter a particular long-text in the current position of a cursor whenever a shortcut key is pressed.
I am thinking of creating a bat file and assigning a windows keyboard shortcut to the bat file and whenever I have requirement to enter the long text, I press the windows shortcut key
and the long text gets typed in the current position of the cursor.
The current position of the cursor can be in any application, like Excel, Word or notepad or Windows dialog prompts.
Could you please let me know if this is possible and point me where I could get some information about this "technique".
Thanks & Regards,
Vasanth.S
To make a single key combo do what you are asking, you may need another program. You can make a link to a batch file, hook up a shortcut and then use the clip command to copy text from a file onto the clipboard. That would require the shortcut and then a Ctrl+V to paste. The batch file would look like this:
clip < c:\SomeDir\sometext.txt
You might like to look at using a clipboard manager - which saves a history of clipboard entries, can search for an entry, and paste it at the cursor.
Ditto and CLCL are both useful and free - which one you use depends on your windows version.
They are hotkey driven for ease of use, but mouse can be used.

How to use vim in the terminal?

How does one setup and start using vim in the terminal on OS X?
I want to start writing my C code using vim in the terminal rather than a separate text editor. How does one get started on this?
The basics like: opening, creating, saving files via terminal using vim and writing code using vim. Also, does one compile directly using vim in the terminal?
Get started quickly
You simply type vim into the terminal to open it and start a new file.
You can pass a filename as an option and it will open that file, e.g. vim main.c. You can open multiple files by passing multiple file arguments.
Vim has different modes, unlike most editors you have probably used. You begin in NORMAL mode, which is where you will spend most of your time once you become familiar with vim.
To return to NORMAL mode after changing to a different mode, press Esc. It's a good idea to map your Caps Lock key to Esc, as it's closer and nobody really uses the Caps Lock key.
The first mode to try is INSERT mode, which is entered with a for append after cursor, or i for insert before cursor.
To enter VISUAL mode, where you can select text, use v. There are many other variants of this mode, which you will discover as you learn more about vim.
To save your file, ensure you're in NORMAL mode and then enter the command :w. When you press :, you will see your command appear in the bottom status bar. To save and exit, use :x. To quit without saving, use :q. If you had made a change you wanted to discard, use :q!.
Configure vim to your liking
You can edit your ~/.vimrc file to configure vim to your liking. It's best to look at a few first (here's mine) and then decide which options suits your style.
This is how mine looks:
To get the file explorer on the left, use NERDTree. For the status bar, use vim-airline. Finally, the color scheme is solarized.
Further learning
You can use man vim for some help inside the terminal. Alternatively, run vimtutor which is a good hands-on starting point.
It's a good idea to print out a Vim Cheatsheet and keep it in front of you while you're learning vim.
Run vim from the terminal. For the basics, you're advised to run the command vimtutor.
# On your terminal command line:
$ vim
If you have a specific file to edit, pass it as an argument.
$ vim yourfile.cpp
Likewise, launch the tutorial
$ vimtutor
You can definetely build your code from Vim, that's what the :make command does.
However, you need to go through the basics first : type vimtutor in your terminal and follow the instructions to the end.
After you have completed it a few times, open an existing (non-important) text file and try out all the things you learned from vimtutor: entering/leaving insert mode, undoing changes, quitting/saving, yanking/putting, moving and so on.
For a while you won't be productive at all with Vim and will probably be tempted to go back to your previous IDE/editor. Do that, but keep up with Vim a little bit every day. You'll probably be stopped by very weird and unexpected things but it will happen less and less.
In a few months you'll find yourself hitting o, v and i all the time in every textfield everywhere.
Have fun!
if you want to open all your .cpp files with one command, and have the window split in as many tiles as opened files, you can use:
vim -o $(find name ".cpp")
if you want to include a template in the place you are, you can use:
:r ~/myHeaderTemplate
will import the file "myHeaderTemplate in the place the cursor was before starting the command.
you can conversely select visually some code and save it to a file
select visually,
add w ~/myPartialfile.txt
when you select visualy, after type ":" in order to enter a command, you'll see "'<,'>" appear after the ":"
'<,'>w ~/myfile $
^ if you add "~/myfile" to the command, the selected part of the file will be saved to myfile.
if you're editing a file an want to copy it :
:saveas newFileWithNewName
If you want to learn by reading yourself:
Open MacOS terminal app.
Write this and press enter -> vimtutor
For quit write this and click -> :q

Manipulating text in XCode, moving one line

In emacs I have various functions to manipulate text. Now that I'm using xcode, I suppose I could make emacs my default editor, but I want to browse obj-c objects and such, so I'd rather just implement my most used text manipulation commands for xcode.
First on my list, I'd like a command that moves the text of the current line up/down one line, keeping the cursor on the current line.
In emacs this is:
(defun move-one-line-downward ()
"Move current line downward once."
(interactive)
(forward-line)
(transpose-lines 1)
(forward-line -1))
I'd be happiest if I could write a script in Python that would do the equivalent in XCode, but as far as I can tell, I need to talk to AppleScript to do this.
Can someone walk me through how to do this with XCode?
Xcode 4 has a new set of command for moving the line where the cursor is or the selected text with command + option + [ or ]
⌄⌘[ or ⌄⌘]
http://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/xcode_help-command_shortcuts/MenuCommands/MenuCommands014.html
What you’re wanting to do can be achieved through Xcode’s “User Scripts”—and it helpfully comes with a pair of scripts that almost do what you want. (I’m using Xcode 3.2 here, but I think these were also there in 3.1)
Look in /Developer/Library/Xcode/User Scripts/; there are two applescripts there, Move Line Up.scpt and Move Line Down.scpt. Here’s what’s in Move Line Up:
(*
To edit this script, choose Save As... and save it in your home directory, then re-add it to the User Scripts list.
*)
using terms from application "Xcode"
tell first text document
set {startLine, endLine} to selected paragraph range
if startLine > 1 then
set theText to (paragraphs startLine through endLine)
set theText to (theText as string)
delete (paragraphs startLine through endLine)
make new paragraph at beginning of paragraph (startLine - 1) with data theText
set selected paragraph range to {startLine - 1, endLine - 1}
else
beep 1
end if
end tell
end using terms from
These almost do what you want, except they select the whole line afterwards; I’m no applescript expert, but you probably want to store the selected character range. Have a look at the Xcode scripting dictionary (in AppleScript Editor, File -> Open Dictionary -> Xcode) to find out the types of objects you can manipulate.
You can add your own scripts to Xcode with the “Edit User Scripts”menu item in the script menu; and assign shortcut keys to the scripts in that window also, by double-clicking in the right-hand column beside the entry for the script menu item.
You can also use shell scripts (perl, python, bash, whatever) in the User Scripts menu, but these process only the selection or the whole file, so might be a bit heavyweight for moving a single line up or down.
See all the docuemntation on User Scripts here: http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeWorkspace/310-User_Scrips/user_scripts.html
I hope this helps!
I think your question is more generic that Xcode/emacs. Most IDE can't do stuff that editors can do and vice versa.
What I do is to use Xcode for 'simple' stuff and compile/debug. When I want to do lot's of coding (hm ... text editing) I open multiple files in one Vim (no offense to emacs ... vim is my editor of choice) and use all the vim tricks available.
I follow the same process when I need to do lots of coding on Windows (Visual Studio). I have VS opened just for compiling/debugging but I do most coding in separate Vim window.
I don't need to do any of that on Unix because I just open file in Vim and run Makefile from within Vim, jumping directly to errors and so on (:mak) ...
I'm sure that there are some extremely clever things to get Xcode do stuff that are already in Vim and Vim to do stuff that Xcode can do but I'm focusing on coding so not much time to play around.
Also, you can hook up emacs (or vi, or bbedit, or ed, I imagine) to xcode, so that they will talk to each other. When you tell xcode to open a file it will call emacsclient, etc. You can even get emacs to tell xcode where to put a breakpoint (I don't remember how, but I asked a question here a while back, and it works great)

Resources