tSIP: mute all other applications

Script (for "on call state" event) muting all other applications during the call, using NirSoft SoundVolumeView. SoundVolumeView.exe has to placed next to tSIP.exe.
Thanks to Carl Fortin.

local call_State_Type = GetCallState()

function file_exists(name)
   local f=io.open(name,"r")
   if f~=nil then io.close(f) return true else return false end
end

local filename = GetExeName()
local index = string.find(filename:reverse(), "\\")
local dir = string.sub(filename, 1, -index)
local exe = dir .. "SoundVolumeView.exe"
-- print(string.format("exe location = %s\n", exe))

if not file_exists(exe) then
	print(string.format("%s does not exist!\n", exe))
	return
end

-- CALL_STATE_ESTABLISHED or CALL_STATE_PROGRESS
if call_State_Type == 6 or call_State_Type == 5 then
    print("Muting all applications except tSIP.exe\n")
    ShellExecute("open", exe, "/Mute AllAppVolume", nil, 1)
    Sleep(500)
    ShellExecute("open", exe, "/Unmute tSIP.exe", nil, 1)
-- CALL_STATE_CLOSED
elseif call_State_Type == 0 then
    print("Unmuting all applications\n")
    ShellExecute("open", exe, "/Unmute AllAppVolume", nil, 1)
else
	-- print("Do nothing!")
end

Back to howto list.