Not for Windows 10. Windows 10 has replaced the old calc.exe with a new one which doesn't work in the same way, so this script will just launch the new calculator on Windows 10 without changing modes.
This scripts adds a new command to Opus: LaunchCalc
The LaunchCalc command opens the Windows Calculator (calc.exe) directly into one of its four modes:
Standard, Scientific, Programmer, and Statistics.
(The script does this by modifying the registry setting calc.exe uses to store the last-used mode.)
[ul][li]For the script to work, the account you're using must have launched calc.exe and changed its mode at least once. The script works by modifying a registry setting and will only modify it if exists already (which happens the first time you change modes). The script won't create the registry setting if it's not already there, in case calc.exe changes where it stores the setting in the future.
[li]The script may fail and do nothing on Windows XP because old versions of calc.exe stored the mode in win.ini instead of the registry.
[li]Not very useful on Windows 10 due to the new Calc.exe.[/li][/ul]
Open Preferences / Toolbars / Scripts, then download LaunchCalc.osp (below) and drag it to the list.
LaunchCalc.osp (1.67 KB)
(If you want to edit it, the .osp file is really a zip file containing the script, with the .zip extension changed to .osp. Change the extension back and you can extract the .vbs file inside and open it in any text editor. You can drop .vbs scripts into the Opus script list directly, without creating an .osp file; the only reason .osp was used here is to make it easier for you to download, since .vbs files are typically blocked.)
Once installed, a new LaunchCalc command will be available in the Button Editor, Hotkey Editor, and so on.
If you run LaunchCalc without any arguments, it will show a pop-up menu where you can select the mode you want calc.exe to use:
You can also tell the command which mode you want to bypass the menu and launch calc.exe directly into a specific mode:
For example, if you often find yourself needing the scientific and programmer modes, you might want to set up a pair of system-wide hotkeys so that you can push one key from any app to open a scientific calc.exe, and another key to open a programmer calc.exe. (Alternatively, don't specify a mode and use just one hotkey, so that when you push the hotkey a menu appears and you can choose from that.)
[li]The script itself:
If you just want to use the script, the LaunchScript.osp download above is probably easier.
The script code is reproduced here so that people looking for scripting techniques on the forum can browse the script code without having to download and extract the .osp file.
' Calculator Launcher
' (c) 2014 Leo Davidson
' This is a script for Directory Opus.
' See http://www.gpsoft.com.au/redirect.asp?page=scripts for development information.
' This script adds a LaunchCalc command to Opus.
' The LaunchCalc command can open the Windows Calculator (calc.exe) directly into one of its four modes
' (Standard, Scientific, Programmer and Statistics). You can tell the command to open in a particular mode,
' using a command-line argument, or you can let it display a pop-up menu.
' Called by Directory Opus to initialize the script
' Provide basic information about the Script
initData.name = "Calculator Launcher"
initData.desc = "Open calc.exe in a specified mode."
initData.copyright = "(c) 2014 Leo Davidson"
initData.default_enable = true
' Initialise the command that this script adds Dim cmd Set cmd = initData.AddCommand() cmd.name = "LaunchCalc" cmd.method = "OnLaunchCalc" cmd.desc = initData.desc cmd.label = "Launch Calculator" cmd.template = "MODE/O[<ask>,standard,scientific,programmer,statistics]"
' Helper function
Function AddMenuFlags(vecFlags, val, test)
If (val = test) Then
' Implements the LaunchCalc command
Const CALC_LAYOUT_STANDARD = 1 Const CALC_LAYOUT_SCIENTIFIC = 0 Const CALC_LAYOUT_PROGRAMMER = 2 Const CALC_LAYOUT_STATISTICS = 3 Const REG_VALUE_PATH_CALC_LAYOUT = "HKCU\Software\Microsoft\Calc\layout" Dim objShell Dim layoutValue Dim layoutNewValue Dim dlgChoice Dim objDlg Dim vecChoices Dim vecCValues Dim vecMenu Dim numValues Dim i Set objShell = CreateObject("WScript.Shell") ' Always read the current layout value, so that if the registry settings aren't there the script will fail. ' (They were not in the registry at all on Windows XP, and could be moved again in the future.) layoutValue = objShell.RegRead(REG_VALUE_PATH_CALC_LAYOUT) layoutNewValue = -1 ' See if a mode was specified via the MODE argument. If ( scriptCmdData.func.args.got_arg.mode ) Then If (scriptCmdData.func.args.mode = "standard") Then layoutNewValue = CALC_LAYOUT_STANDARD ElseIf (scriptCmdData.func.args.mode = "scientific") Then layoutNewValue = CALC_LAYOUT_SCIENTIFIC ElseIf (scriptCmdData.func.args.mode = "programmer") Then layoutNewValue = CALC_LAYOUT_PROGRAMMER ElseIf (scriptCmdData.func.args.mode = "statistics") Then layoutNewValue = CALC_LAYOUT_STATISTICS End If End If ' If we don't now which mode we want, use a pop-up menu to ask the user. If (layoutNewValue < 0) Then Set vecChoices = DOpus.NewVector Set vecCValues = DOpus.NewVector Set vecMenu = DOpus.NewVector vecChoices.push_back "&Standard" vecCValues.push_back CALC_LAYOUT_STANDARD vecChoices.push_back "S&cientific" vecCValues.push_back CALC_LAYOUT_SCIENTIFIC vecChoices.push_back "&Programmer" vecCValues.push_back CALC_LAYOUT_PROGRAMMER vecChoices.push_back "S&tatistics" vecCValues.push_back CALC_LAYOUT_STATISTICS vecChoices.push_back "-" vecChoices.push_back "Cancel" ' Make the item for the last used mode bold. For i = 0 To vecCValues.size - 1 AddMenuFlags vecMenu, layoutValue, vecCValues(i) Next Set objDlg = scriptCmdData.func.Dlg objDlg.choices = vecChoices objDlg.menu = vecMenu dlgChoice = objDlg.Show() dlgChoice = dlgChoice - 1 ' Convert to 0-based index, -1 meaning nothing was selected. If (dlgChoice < 0 Or dlgChoice >= vecCValues.size) Then layoutNewValue = -1 Else layoutNewValue = vecCValues(dlgChoice) End If End If ' If we now know the mode to use, launch calc.exe, changing the registry value first if needed. If (layoutNewValue > -1) Then If (layoutValue <> layoutNewValue) Then objShell.RegWrite REG_VALUE_PATH_CALC_LAYOUT, layoutNewValue, "REG_DWORD" End If objShell.Run "%windir%\system32\calc.exe", 1, False End If