Page 1 of 2

cm_SwitchInternalAssociations

Posted: 2022-10-17, 10:26 UTC
by KozakMak
By analogy with cm_SwitchDarkmode.
When the button on toolbar is pressed they are on, when not - they are off.

Re: cm_SwitchInternalAssociations

Posted: 2022-10-24, 05:14 UTC
by Fla$her
Support. Although my script is enough for me:

Code: Select all

'——————————————————————— VBS ———————————————————————
' Purpose: On/off internal associations in TC
'—————————————————— Path to ТСFS2 ——————————————————
TCFS2 = """%COMMANDER_PATH%\Utils\TCFS2\TCFS2.exe"""
'——————————————————————————————— Author: Flasher © —
Set WSS = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
INI = WSS.Environment("PROCESS")("COMMANDER_INI")
Text = FSO.OpenTextFile(INI, 1,, -2).ReadAll
Find1 = InStr(Text, vbLf & "[Associations]")
Find2 = InStr(Text, vbLf & "[-Associations]")
If Find1 Then
   If Mid(Text, Find1 + 17, 16) = "RedirectSection=" Then
      Str = Split(Mid(Text, Find1 + 33, 260), vbCr)(0)
      Select Case True
         Case Str = "0" Or Str = ""
         Case Str = "1"
            Str = WSS.ExpandEnvironmentStrings(Split(Mid(Text, _
            InStr(Text, vbLf & "AlternateUserIni=") + 18, 260), vbCr)(0))
            If FSO.FileExists(Str) Then
               INI  = Str
               Text = FSO.OpenTextFile(INI, 1,, -2).ReadAll
               Find1 = InStr(Text, vbLf & "[Associations]")
               Find2 = InStr(Text, vbLf & "[-Associations]")
               If Find1 Then
                  Text = Left(Text, Find1 + 1) & "-" & Mid(Text, Find1 + 2)
               ElseIf Find2 Then
                  Text = Left(Text, Find2 + 1) & Mid(Text, Find2 + 3)
               End If
            End If
         Case Else
            Str = WSS.ExpandEnvironmentStrings(Str)
            If FSO.FileExists(Str) Then
               INI = Str
               Set Text = FSO.OpenTextFile(INI, 1,, -2)
               If Not Text.AtEndOfStream Then
                  Select Case Text.ReadLine
                     Case "[Associations]" Dash = "-"
                     Case "[-Associations]"
                     Case Else WSH.Quit
                  End Select
                  Text = "[" & Dash & "Associations]" & vbCrLf & Text.ReadAll
               Else WSH.Quit() End If
            End If
      End Select
   Else Text = Left(Text, Find1 + 1) & "-" & Mid(Text, Find1 + 2)
   End If
ElseIf Find2 Then
   Text = Left(Text, Find2 + 1) & Mid(Text, Find2 + 3)
End If
If Find1 + Find2 Then
   With FSO.OpenTextFile(INI,2,,-2) .Write Text: .Close: End With
   WSS.Run TCFS2 & " /ef msg(147,0,1302100) tcm(2958)",, 1
End If
Set WSS = Nothing: Set FSO = Nothing

Re: cm_SwitchInternalAssociations

Posted: 2022-10-31, 19:03 UTC
by yanch
Vote +1

2Fla$her
Is it possible to use this script with custom View Modes (Auto-run commands)?

Re: cm_SwitchInternalAssociations

Posted: 2022-10-31, 22:25 UTC
by Fla$her
2yanch
Create an em_ command with a path to .vbs and call it.

Re: cm_SwitchInternalAssociations

Posted: 2022-11-02, 21:33 UTC
by yanch
2Fla$her
Could you please paste "bar button" or "em_command" here? I do smth wrong and it doesn`t work.

Re: cm_SwitchInternalAssociations

Posted: 2022-11-03, 04:43 UTC
by Fla$her
Except the path to .vbs there is nothing there.
In the header of the script there is a path to TCFS2. Did you fix it to yours?

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 09:55 UTC
by yanch
Sorry, there is another fail. Redirections are set in wincmd.ini file.
screen
So how to edit this script for my case?

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 10:12 UTC
by Fla$her
yanch wrote: 2022-11-04, 09:55 UTCSorry, there is another fail.
What exactly is the fail?

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 11:06 UTC
by yanch
Fla$her wrote: 2022-11-04, 10:12 UTC What exactly is the fail?
Redirections are set in my wincmd.ini. So [Associations] section is placed in separate "associations-searches.INI" file.
Look at the screenshot
screen
And the script fails to run in this situation. It works only if I move [Associations] section back to the standard place - wincmd.ini. Is it possible to modify the script in order to work within my case?

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 11:26 UTC
by KozakMak
2yanch
easier to use TCASwitcher

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 11:32 UTC
by Fla$her
yanch wrote: 2022-11-04, 11:06 UTCAnd the script fails to run in this situation.
I was just asking about that.

For some reason I was sure that TC first reads the name of the section, but it turned out that it keeps information about the redirection in memory.
OK, I'll fix it a bit later.

2KozakMak
No. It's a legacy solution through confirmation in dialogue.

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 12:47 UTC
by KozakMak
Fla$her wrote: 2022-11-04, 11:32 UTC No. It's a legacy solution through confirmation in dialogue.
...but it has colorful button to identify its on or off

Re: cm_SwitchInternalAssociations

Posted: 2022-11-04, 19:50 UTC
by Fla$her
Fla$her wrote: 2022-11-04, 11:32 UTCOK, I'll fix it a bit later.
Done.
KozakMak wrote: 2022-11-04, 12:47 UTC ...but it has colorful button to identify its on or off
It does this by default in Default.bar, i.e. when called from another bar, instead of updating the icon for the current toolbar, it will switch to Default.bar, where the icon will change, which is unacceptable. And even if you make an edit for em_RefreshBar manually, the icon will change only for a single bar, and not at all for the current one. In addition, when restarting TC, there is no re-reading of the value and the button may not correspond to the current status if the switch was made in another way, including manual editing of ini files.
But since it is planned to read/write files in Autorun, this problem can be solved completely (without third-party tools) already there. When such an opportunity arises, I will post the solution here.

Re: cm_SwitchInternalAssociations

Posted: 2022-11-05, 06:40 UTC
by KozakMak
Fla$her wrote: 2022-11-04, 19:50 UTC I will post the solution here.
wow :shock:
I'll be waiting!

Re: cm_SwitchInternalAssociations

Posted: 2022-11-05, 06:49 UTC
by Fla$her
Fla$her wrote: 2022-11-04, 19:50 UTCwithout third-party tools
A little hasty. This will solve the icon problem after restarting, but not when the button is pressed. To click, we'll need TCFS2.