Originally Posted by
jaap.spierenburg
How to implement this in Lisp?
Edit: WARNING - Use at your own risk.
Edit: Code revised such that the respective objects are supplied as an argument to reduce the number of time each is created and released.
First, download the applicable version of nircmd.exe: 32 Bit, 64-Bit, More on nircmd.exe
Second, use the applicable function for your needs:
Code:
(defun MUTE (oShell i / )
;; © RenderMan 2011
;; Example (mute <ShellObject> <Option>)
;; Arguments:
;; <ShellObject> "WScript.Shell" object
;; <Option> An integer of 0, 1, or 2
;; 0=Unmute, 1=Mute, 2=Toggle
(if (findfile "nircmd.exe")
(vlax-invoke
oShell
'run
(strcat "nircmd.exe mutesysvolume "
(itoa (fix i))))
(prompt "\n** Cannot find \"nircmd.exe\" ** "))
(princ))
Code:
(defun SETVOLUME (oShell vol /)
;; © RenderMan 2011
;; Example (setvolume <ShellObject> <Volume%>)
;; Arguments:
;; <ShellObject> "WScript.Shell" object
;; <Volume%> Real or integer equal to, or between 0 and 1
(if (findfile "nircmd.exe")
(progn
(vlax-invoke oShell 'run "nircmd.exe changesysvolume -65535")
(vlax-invoke
oShell
'run
(strcat "nircmd.exe changesysvolume "
(itoa (fix (* vol 65535.))))))
(prompt "\n** Cannot find \"nircmd.exe\" ** "))
(princ))
Edit: There's a time and place for everything... even fun at the workplace:
Code:
(defun TellUser (string / *error* sayit oShell oSapi)
;; © RenderMan 2011
;; Example (TellUser "Hey, You! Get back to work. Hah zah!")
;; Arguments:
;; string Phrase to be spoken by Sapi.SpVoice object
(vl-load-com)
(defun *error* (msg)
(and oShell
(setq oShell
(vl-catch-all-apply 'vlax-release-object (list oShell))))
(and oSapi
(setq oSapi
(vl-catch-all-apply 'vlax-release-object (list oSapi))))
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** ")))) ; Fatal error, display it
(princ))
(defun sayit (oSapi string /)
;; © RenderMan 2011, inspired by Patrick_35
;; Linky: http://www.theswamp.org/index.php?topic=14549.0
(vlax-invoke oSapi 'speak string 0)
(princ))
(if (and (setq oShell (vlax-get-or-create-object "WScript.Shell"))
(setq oSapi (vlax-get-or-create-object "Sapi.SpVoice")))
(progn
(mute oShell 0)
(setvolume oShell 0.50)
(sayit oSapi string)
(*error* nil))
(cond (oShell (*error* "Could not create \"Sapi.SpVoice\" object"))
((*error* "Could not create \"WScript.Shell\" object")))))
Happy coding!