Option Explicit ' 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 Function OnInit(initData) ' 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[,standard,scientific,programmer,statistics]" End Function ' Helper function Function AddMenuFlags(vecFlags, val, test) If (val = test) Then vecFlags.push_back 1 Else vecFlags.push_back 0 End If End Function ' Implements the LaunchCalc command Function OnLaunchCalc(scriptCmdData) 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 End Function