How can I call another voice command with advanced scripting? - naturallyspeaking

I am writing a voice command using Advanced Scripting in Dragon NaturallySpeaking 12.5 professional (Windows 7 SP1 x64 Ultimate). How can I call another voice command?

You can use the command HeardWord.
E.g. if you want to call the command my voice command then you can call it from another advanced script as follows:
Sub Main
HeardWord "my", "voice", "command"
End Sub
Another example, say you want to automatically write down [name](link) assuming that you have link as the most recent clipboard and name as the second most recent clipboard (using Ditto to manage the clipboard history), you can use the command:
Sub Main
originalClipboard = Clipboard
SendKeys " ["
HeardWord "paste", "two"
Wait(1)
Clipboard("](" & originalClipboard & ")")
SendKeys "^v"
Wait(1)
Clipboard(originalClipboard)
End Sub

Related

How do I add a keyboard shortcut to open VS Code on the folder from File Explorer?

I want to be able to press . in any folder that I'm in File Explorer and open Visual Studio Code on that folder. It is the same effect as right-clicking and clicking "Open with Code". Pressing . is just like I could do on the GitHub website.
It might not be officially possible, but are there any workarounds to make it work?
The biggest issue is getting the current location from windows explorer. This requires some reverse engineering to get the memory address where windows explorer stores the location. If for any reason this address changes, you will need to find it again.
Besides that, windows supports global keyboard hooks. So you'd like to set up a global keyboard hook for your . key. The windows API also provides methods to get the active window. So whenever the . key is pressed, you can check that the active window is an explorer window. Then you'd read the current folder from the explorer window's memory. After that you've got everyting you need to start visual studio code.
This is very hacky, but I guess it's the only choice you have. Topics to research are:
Keyloggers - These for instance use the global hooks I mentioned
Generic reverse engineering - To find the address of the current location in windows explorer
Edit: Autohotkey post about how to get the windows explorer location. If that works as people claim, autohotkey can also be used to register a hook for the . key and launch VS code.
Thank you #AdrAs and #SarvinR for the answers. I used Sarvin's solution for a while, while trying to google and make sense of Adr's solution. Sarvin's solution is very useful if you're not trying to download any external programs, but if you want the true solution to this question, I finally managed it here:
Download AutoHotKey. It's good if you're familiar with it. AHK basically creates hotkeys (or shortcuts) like Adr described.
(If you have an existing ahk that you use, you can skip these steps and copy the code block down below)
Create a new AutoHotKey script by right-clicking on your desktop or anywhere in file explorer (we're gonna move it later so it doesn't matter). Name it whatever you want. I'm going to call it MyScript.ahk for this answer (I actually used david.ahk for myself).
Now, open command prompt (win + r, cmd, enter) and look for where VSCode is by typing where code. It will probably give you two lines. Take note of one of the lines (I chose the top one).
Right-click the ahk script file that you just created and choose Edit Script (or you can open it with notepad++ or VSCode or any editor of your choice, it's just a normal text file). Delete everything and paste this in:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
GetActiveExplorerPath()
{
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}
#IfWinActive ahk_exe Explorer.exe
.::
path := GetActiveExplorerPath()
run, "C:\Users\david\AppData\Local\Programs\Microsoft VS Code\bin\code" "%path%"
return
On the second last line, replace the VSCode location with what you just saw in cmd. You most likely have to just change the username from david to your name.
Now, save the file try opening it (double click the ahk). If it works, a green H icon should appear on your tray without any errors. Go into any file directory in Windows File Explorer and hit . like you would normally do in GitHub. (Do Not do this in large directories like your root C:. There will be too many files for VSCode to load). It should work like expected, and if it doesn't, you did something wrong (I did the exact same thing like I just described and it works).
Now, of course, you would want to run this script on startup. Copy/Move the .ahk file into C:\Windows\System32. It will ask you for administrator permissions, so click yes. Open the registry editor (win + r, regedit, enter). Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. On the right side pane, right click on the empty space then create a new String Value with any name (I used davidAHK) and set its value to your ahk file that you just copied/moved with quotes ("C:\Windows\System32\david.ahk" for my case). Close the Registry Editor and safely restart your computer. The ahk script should run on start up and you should be able to click . in any directory in file explorer to open VSCode.
Again, thank you #AdrAs and #SarvinR for your help!
I have an trick for this
Create vs.bat and write this code in that
#echo off
code %cd%
And Move this file to C:/Windows/System32/
Now All Set.
If you type vs on the address bar of explorer your vs code with current folder will open
open VSCode -> command+shift+p -> Enter shell command – > click the prompt "shell command: install 'code' command in path"
open directory -> code .
I wanted launch VS Code with the open folder OR the selected files, using AHK v2, and I wanted it to be plug & play for other users. Here's the result:
#Requires AutoHotkey v2.0
; This is the key combo.
#!.::
{
; Is the current window an Explorer window?
if (WinGetClass("A") == "CabinetWClass") {
; Cache the current clipboard contents.
clipboard := A_Clipboard
; Clear the clipboard & copy selected files.
A_Clipboard := ""
Send "^c"
ClipWait(0.5)
; If no files are selected...
if (A_Clipboard == "") {
; Get the current window's ID.
hwnd := WinGetID("A")
; Find the current window's COM object.
for window in ComObject("Shell.Application").Windows{
if (window && window.hwnd && window.hwnd == hwnd)
; Get the current folder's path.
path := window.Document.Folder.Self.Path
}
}
else {
; Quote & space-concatenate selected files.
path := '"' . StrReplace(A_Clipboard, "`n", '" "') . '"'
}
; Restore the clipboard.
A_Clipboard := clipboard
; Run code.
exe := '"' . StrReplace(A_AppData, "Roaming", "Local\Programs\Microsoft VS Code\code") . '"'
Run(exe . " " . path)
}
}
Works like a charm, and it's a piece of cake to install & run on your machine! Instructions at the repo.

How can I start multiple integrated terminal panels with a click?

Within Visual Studio Code, I'd like to have the possibility to push a button or run a command that would create multiple terminal panels and run commands on them.
This is useful especially when dealing with code stored into frequently unmounted drives, where every time you mount it you have to start a few terminals and navigate to the proper directories.
Is it possible?
On Mac we can leverage the power of AppleScript to accomplish this.
Firstly, we need to add a keystroke for creating a new terminal instance:
{ "key": "cmd+n", "command": "workbench.action.terminal.new",
"when": "terminalFocus" }
Secondly, we create an AppleScript, like the following:
tell application "Visual Studio Code" to activate
tell application "System Events"
# Term 1
keystroke "`" using control down
keystroke "cd path/number/1"
keystroke return
# Term 2
keystroke "n" using command down
keystroke "cd path/number/2"
keystroke return
# Term 3
keystroke "n" using command down
keystroke "cd path/number/3"
keystroke return
# End
keystroke "`" using control down
end tell
Lastly, we add a VSC Task with the command:
osascript ./my_script.scpt
And then just run the task.
I hope somebody will find this helpful.

Substitute AltTab in one key

Is it possible to substitute AltTab with only one key press ?
i tried this one but it doesn't work
`::AltTab
I use this, you may need to change the Sleep delay.
`::
Send {Alt Down}{Tab}
Sleep 100
Send {Alt Up}
return
I am running Windows 8.1 64-bit and AutoHotkey v1.1.16.05. And my C:\Program Files\AutoHotkey\AutoHotkeyU64.exe is digitally signed by running the script described here (EnableUIAccess.zip) so that Windows allows it to simulate Alt+Tab. The digital sign is required if you are using Windows Vista and onwards.
Download the zip file and extract it. Then run EnableUIAccess.ahk:
It will ask which AutoHotkey executable to sign. Pick one that you need (AutoHotkeyA32.exe, AutoHotkeyU32.exe, AutoHotkeyU64.exe or AutoHotkey.exe).
Then it will ask to save the new executable. You can choose to overwrite the original file or save as another executable.
Finally it will ask to create a "Run Script with UI Access" context menu item. If you choose 'Yes', then you can right-click a .ahk file and choose "Run Script with UI Access", which will use the digitally signed executable to run the .ahk file. But if you choose to overwrite the original file in step 2, then it is not necessary to create this context menu item.
From the docs:
Each Alt-Tab hotkey must be a combination of two keys, which is typically achieved via the ampersand symbol (&).
http://ahkscript.org/docs/Hotkeys.htm#AltTabDetail
You might even be able to avoid messing around with UIAccess and administrator privileges. This works for me on Windows 8.1:
`::Run "C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk"
And for others who are struggling with getting a two-key combination working on Windows 8 or 10, here's an example using Ctrl-Tab to trigger the window switcher:
^Tab::
Run "C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk"
SetTimer EnterOnKeyUp, -1
return
EnterOnKeyUp:
WinWaitActive ahk_class TaskSwitcherWnd
KeyWait Ctrl
Send {Enter}
SetTimer EnterOnKeyUp, Off
return
* Inspired by: Fully Working Alt Tab Win 8

Running a MATLAB script from Notepad++

Is there a way of running a MATLAB script from Notepad++?
Obviously I have MATLAB installed on my computer. I know you can set a path for Notepad++to run when you hit F5, but when I set this path to my MATLAB.exe file, it simply opens another instance of MATLAB.
This is not what I want, I want the actual script in Notepad++ to be executed in the already open and running instance of MATLAB.
I'm afraid I'm not on my home computer at the moment to test this out, so the following is just a suggestion for you to try.
If you take a look at the NppExec plugin for Notepad++, you'll see that with it you can specify a command to be run when you hit F6 (like an enhanced version of hitting F5 in the regular Notepad++). You can also give it variables such as the path to the current file, and the name of the current file.
MATLAB (on Windows at least - I assume you're on Windows) makes available an API over ActiveX/COM. If you search in the MATLAB documentation for details, it's under External Interfaces -> MATLAB COM Automation Server. By running (in MATLAB) the command enableservice('AutomationServer') you will set up your running instance of MATLAB to receive instructions over this API.
You should be able to write a small script (perhaps in VBScript or something similar) that will take as input arguments the path and filename of the current file in Notepad++, and will then connect to a running instance of MATLAB over the COM API and execute the file's contents.
Set this script to be executed in NppExec when you hit F6, and it should then run the current file in the open instance of MATLAB.
As I say, the above is just speculation as I can't test it out right now, but I think it should work. Good luck!
Use NppExec add-on and press F6, copy paste the following and save the script:
NPP_SAVE
set local MATPATH=C:\Program Files\MATLAB\R2015a\bin\matlab.exe
cd "$(CURRENT_DIRECTORY)"
"$(MATPATH)" -nodisplay -nosplash -nodesktop -r "try, run('$(FILE_NAME)'),
catch me, fprintf('%s / %s\n',me.identifier,me.message), end"
then run (press F6; enter). Matlab Console and Plot windows still open and stay open. Error messages will be displayed in opening Matlab command window. Adding
, exit"
to the last command will make it quit and close again. If you want to run an automated application with crontabs or the like, check Matlab external interface reference for automation.
matlab.exe -automation ...
Also works in cmd terminal, but you have to fill in the paths yourself.
This is a usable implementation upon Sam's idea. First, execute MATLAB in automation mode like this.
matlab.exe -automation
Next, compile and execute this following VB in NppExec plugin. (which is to use MATLAB automation API)
'open_matlab.vb
Imports System
Module open_matlab
' connect to a opened matlab session
Sub Main()
Dim h As Object
Dim res As String
Dim matcmd As String
h = GetObject(, "Matlab.Application")
Console.WriteLine("MATLAB & Notepad++")
Console.WriteLine(" ")
'mainLoop
while True
Console.Write(">> ")
matcmd = Console.ReadLine()
' How you exit this app
if matcmd.Equals("!!") then
Exit while
End if
res=h.Execute(matcmd)
Console.WriteLine(res)
End while
End Sub
End Module
Then you'll get a matlab-like terminal below your editor. You can then code above and execute below. type !! to exit the terminal.
What it looks like
Tips: don't use ctrl+c to interrupt the MATLAB command, because it will kill the whole process instead.

Outlook rule to run VBA script to pass the body of email to external program

I've set up an Outlook rule that filters emails. I want to run an external program (python script) to parse each such email.
I know of the SHELL function, but I need a way to pass the body of the email to my external program.
Google is your friend for this one, I got this snippet by searching "outlook vba script".
Basically for the body of the email you want to pass Item.Body to your python script.
http://support.microsoft.com/kb/306108
Sub CustomMailMessageRule(Item As Outlook.MailItem)
MsgBox "Mail message arrived: " & Item.Subject
End Sub`
Sub CustomMeetingRequestRule(Item As Outlook.MeetingItem)
MsgBox "Meeting request arrived: " & Item.Subject
End Sub
You'd need a VBA script to parse python in outlook.
Press alt+F11. You will get a VBA window.
Sub python(Item As Outlook.MailItem)
Shell ("python C:\path\tp\your\filename.py")
End Sub
I hope you have set windows variable path for python.
Shell command passes the command to windows shell prompt. You can test this by running your python script in command prompt. If it is working there, then it should work here as well.