[WDX] Autorun Plugin: Run commands/set envvars on TC start

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You may start via plugin any apps that you start from batch. Just use ShellExec command like this:

Code: Select all

# Open Quick View on left panel
ShellExec "%COMMANDER_PATH%\Addons\TCFS2\TCFS2.exe" "/ef tcm(104)"
Currently plugin can't check if some app is running (only via bat file that is started from plugin), but it was requested (and will be realized as plugin I think).
tcvol
Junior Member
Junior Member
Posts: 67
Joined: 2009-02-02, 12:35 UTC

Post by *tcvol »

MVV wrote:You may start via plugin any apps that you start from batch. Just use ShellExec command like this:

Code: Select all

# Open Quick View on left panel
ShellExec "%COMMANDER_PATH%\Addons\TCFS2\TCFS2.exe" "/ef tcm(104)"
Currently plugin can't check if some app is running (only via bat file that is started from plugin), but it was requested (and will be realized as plugin I think).
cool, please let us know when you implement such a "onlystartifnotrunning" parameter ;-)

until then i will stick with a .cmd using pslist.exe, find.exe and handle.exe :-)
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

tcvol wrote:hi there

can you please post a few more examples to get more ideas of the .cfg file?
i have quite a lot of .cmd before/while tc starts, which are probably still needed, since tc has to be mounted and started from within a truecrypt volume and i need the information before tc is started.

but i think i could migrate the following things:
path to be synced (dropbox)
path not to be synced (tcmd addons)
start 3rd party apps if not already running

cheers
You could use AutoHotkey for the latter.

Code: Select all

ShellExec /ec %USERPROFILE%\Documents\AutoHotkey\TC_StartApps.ahk

Code: Select all

; TC_StartApps.ahk
if(!WinExist("Untitled ahk_class Notepad") )
   Run, notepad.exe
And if AutoRun.wdx can run cmd.exe, there's little difference to using

CMD.exe START "" Program.exe
OR
CMD.exe START "" FileWith.Extension
VS "ShellExec"

E.G, if file "Test.txt" exists, then these two commands do the exact same thing.

---> ShellExec Test.txt
---> CMD /c START "" Test.txt

Further, within an AHK script, the "Run" command will work similiarly as well, e.g.
Run, Test.txt


If "Test.txt" doesn't exist, then as is, none of those commands will be able to auto-create/open it in the default application.

Except AHK and CMD could check for existence of the file and do something specific if it doesn't exist instead.
sgp
Senior Member
Senior Member
Posts: 355
Joined: 2005-01-31, 16:04 UTC

Post by *sgp »

I think ShellExec will only work if the Windows shell is running (granted that's 99.9% of cases) and if a file association for .ext is stored in the System Registry, which is not guaranteed, especially since tcvol is running a portable installation.

I have defined all my portable apps as TC portable associations. Can AHK look up a file extension and return the command line(s) that TC associates to open that extension?
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

You will need some script/tool that will read TC internal associations section and check if given file may be assosiated with one of existing IA templates.
tcvol
Junior Member
Junior Member
Posts: 67
Joined: 2009-02-02, 12:35 UTC

Post by *tcvol »

ok I really like this plugin. here is what I am using this .cfg

Code: Select all

# Enables MoveButton functionality
# Âêëþ÷àåò ôóíêöèîíàë MoveButton
#LoadLibrary Plugins\Autorun_MoveButton.dll
#MoveOptionsButton MOVE_LEGACY

# Adding current TC path to PATH environment variable
# Äîáàâëÿåò ê ïåðåìåííîé îêðóæåíèÿ PATH òåêóùóþ ïàïêó TC

SetEnv /A /EV AUTORUN_OSVERSION %AUTORUN_OSVERSION%
SetEnv /A /EV COMMANDER_ADDONS %COMMANDER_PATH%\..\..\tcmdaddons
SetEnv /A /EV COMMANDER_WS %COMMANDER_PATH%\..\..\tcmdws
SetEnv /A /EV COMMANDER_SCRIPTS %COMMANDER_PATH%\.scripts

SetEnv /EV cut %COMMANDER_PATH%\ess\util\gnu\cut.exe
SetEnv /EV head %COMMANDER_PATH%\ess\util\gnu\head.exe
SetEnv /EV ssed %COMMANDER_PATH%\ess\util\gnu\ssed.exe
SetEnv /EV tail %COMMANDER_PATH%\ess\util\gnu\tail.exe

#utils
#SetEnv /AD /EV cut %COMMANDER_PATH%\ess\util\gnu\cut.exe
#SetEnv /AD /EV handle %COMMANDER_PATH%\ess\sys\sysinternals\pstools\handle.exe
#SetEnv /AD /EV head %COMMANDER_PATH%\ess\util\gnu\head.exe
#SetEnv /AD /EV pskill %COMMANDER_PATH%\ess\sys\sysinternals\pstools\pskill.exe
#SetEnv /AD /EV pslist %COMMANDER_PATH%\ess\sys\sysinternals\pstools\pslist.exe
#SetEnv /AD /EV pwd %COMMANDER_PATH%\ess\util\gnu\pwd.exe
#SetEnv /AD /EV ssed %COMMANDER_PATH%\ess\util\gnu\ssed.exe
#SetEnv /AD /EV tail %COMMANDER_PATH%\ess\util\gnu\tail.exe
#SetEnv /AD /EV wc %COMMANDER_PATH%\ess\util\gnu\wc.exe
#SetEnv /AD /EV setx %COMMANDER_PATH%\ess\util\cli\setx.exe

# Enables showing of administrative shares
# Âêëþ÷àåò îòîáðàæåíèå àäìèíèñòðàòèâíûõ øàð
#SendCommand cm_AdministerServer

#set ditto db to expanded tc workspace\ditto.db
#ini write
#IniWrite %commander_path%\ess\util\ditto\Ditto.Settings Ditto DBPath3 %commander_ws%\ditto.db

#fix favmenu path to tc
IniWrite /EV %commander_path%\ess\tcmd\favmenu\config.ini TcFavMenu tcExe %commander_path%\TOTALCMD.EXE
IniWrite /EV %commander_path%\ess\tcmd\favmenu\config.ini TcFavMenu tcIni %commander_ws%\dirmenu.ini

#call tc startup script
#ShellExec "%commander_scripts%/sys/pause.cmd"
ShellExec /EV %commander_scripts%/autotc/startup.3.cmd
since there is a lot autorun can't do I still need another startup script:

Code: Select all

@echo off
REM set logging file
set log=%TEMP%\%~n0.log

date /T > "%log%"
time /T >> "%log%"

REM clean up tasks
REM clear captchas of jdownloader because of syncing
if exist "%commander_path%\ess\www\jdownloader\captchas\*.*" (
echo [i] deleting "%commander_path%\ess\www\jdownloader\captchas\*.*" >> "%log%" && del "%commander_path%\ess\www\jdownloader\captchas\*.*" /Q
)

echo @echo off > "%TEMP%\%~n0.run.cmd"

REM checking running apps
REM apps.ini
for /f "usebackq delims=* tokens=1,2" %%a in ("%~dp0apps.ini") do (
echo [i] calling "%commander_path%\.scripts\sys\exist.exe" %%a "%%b\%%a" "%%b" >> "%log%" && echo "%commander_path%\.scripts\sys\exist.exe" %%a %%b\%%a %%b >> "%TEMP%\%~n0.run.cmd"

)

if exist "%TEMP%\%~n0.run.cmd" call "%TEMP%\%~n0.run.cmd"

REM tc pre tasks workspace
REM copy local.bar if it doesn't exist locally
if not exist "%commander_ws%\local.bar" (
echo [i] "%commander_ws%\local.bar" does not exist, copying from "%commander_path%\profiles\my\bars\Bar_02.bar" >> "%log%" && copy "%commander_path%\profiles\my\bars\Bar_02.bar" "%commander_ws%\local.bar"
)

REM checking tc hotlist
if exist "%commander_ws%\dirmenu.ini" (


echo [i] checking entries of "%commander_ws%\dirmenu.ini" >> "%log%"
echo [i] exporting remotestart to remoteend to "%commander_ws%\dirmenu.ini.combined" >> "%log%" && "%ssed%" -n "/;remotestart/,/;remoteend/p" "%commander_path%\profiles\my\dirmenu.ini" > "%commander_ws%\dirmenu.ini.combined"
echo [i] exporting localstart to localend to "%commander_ws%\dirmenu.ini.local" >> "%log%" && "%ssed%" -n "/;localstart/,/;localend/p" "%commander_ws%\dirmenu.ini" > "%commander_ws%\dirmenu.ini.local"
"%tail%" -n 2 "%commander_ws%\dirmenu.ini.combined" | find "=" | "%cut%" -d = -f 1 | "%ssed%" -e "s/[^0-9]//g" > "%temp%\%~n0.endremote.nfi"
"%head%" -n 2 "%commander_ws%\dirmenu.ini.local" | find "=" | "%cut%" -d = -f 1 | "%ssed%" -e "s/[^0-9]//g" > "%temp%\%~n0.startlocal.nfi"
setlocal enabledelayedexpansion
set /p endremote=<"%temp%\%~n0.endremote.nfi"
set /p startlocal=<"%temp%\%~n0.startlocal.nfi"
set /a localconst=!startlocal!-1
echo [d] endremote: !endremote! startlocal: !startlocal! localconst: !localconst! >> "%log%"
echo [i] copying combined "%workspace%\dirmenu.ini.combined" to "%commander_ws%\dirmenu.ini" && copy "%commander_ws%\dirmenu.ini.combined" "%commander_ws%\dirmenu.ini"
echo ;localstart >> "%commander_ws%\dirmenu.ini"

for /f "usebackq tokens=1,2 delims==" %%a in ("%commander_ws%\dirmenu.ini.local") do (
  echo %%a | "%ssed%" -e "s/[^0-9]//g" > "%temp%\%~n0.temp1.nfi"
  echo %%a | "%ssed%" -e "s/[0-9]//g" > "%temp%\%~n0.temp2.nfi"
  set /P temp1=<"%temp%\%~n0.temp1.nfi"
  set /P temp2=<"%temp%\%~n0.temp2.nfi"
  set temp2=!temp2:~0,-1!
  set /A calc1=!temp1!-!localconst!+!endremote!
  echo [i] appending to final hotlist: !temp2!!calc1!=%%b >> "%log%" && echo !temp2!!calc1!=%%b >> "%commander_ws%\dirmenu.ini"
)
echo [i] appending ;localend  to final hotlist >>  "%log%" && echo ;localend >> "%commander_ws%\dirmenu.ini"


)

if not exist "%commander_ws%\dirmenu.ini" echo [i] "%commander_ws%\dirmenu.ini" does not exist, copying from "%commander_path%\profiles\my\dirmenu.ini" >> "%log%" && copy "%commander_path%\profiles\my\dirmenu.ini" "%commander_ws%\"

if exist "%TEMP%\%~n0.*.nfi" echo [i] deleting "%TEMP%\%~n0.*.nfi" >> "%log%" && del "%TEMP%\%~n0.*.nfi"
tcvol
Junior Member
Junior Member
Posts: 67
Joined: 2009-02-02, 12:35 UTC

Post by *tcvol »

sgp wrote:I think ShellExec will only work if the Windows shell is running (granted that's 99.9% of cases) and if a file association for .ext is stored in the System Registry, which is not guaranteed, especially since tcvol is running a portable installation.

I have defined all my portable apps as TC portable associations. Can AHK look up a file extension and return the command line(s) that TC associates to open that extension?
not sure if you mean this .. but this works :D

internal associations

Code: Select all

*.ahk
"%commander_path%\ess\util\autohotkey\AutoHotkey.exe" "%1"
sgp
Senior Member
Senior Member
Posts: 355
Joined: 2005-01-31, 16:04 UTC

Post by *sgp »

tcvol wrote:
sgp wrote:I think ShellExec will only work if the Windows shell is running (granted that's 99.9% of cases) and if a file association for .ext is stored in the System Registry, which is not guaranteed, especially since tcvol is running a portable installation.

I have defined all my portable apps as TC portable associations. Can AHK look up a file extension and return the command line(s) that TC associates to open that extension?
not sure if you mean this .. but this works :D

internal associations

Code: Select all

*.ahk
"%commander_path%\ess\util\autohotkey\AutoHotkey.exe" "%1"
No, this isn't waht I meant with my question. I meant can AHK read TC internal associations section and check if a given file is associated with some existing templates, and return a menu of such templates.

I scripted the above with Take Command - a CMD replacement - and I'm interested in finding an equivalent AHK script.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Autorun 1.6 Beta 13
There were many new features have been added (and bugs fixed) since Beta 3, here are a little part of changelog:
readme_en.txt wrote:1.6 beta 13
+ added %ERROR% variable functionality
+ added commands SystemParametersInfo, GetSysColor into SysInfo plugin
+ basic functions for working with strings

1.6 beta 12
+ added API for С++
+ added Sysinfo plugin

1.6 beta 11
+ command RegRead

1.6 beta 10
+ /WAIT parameter for ShellExec
+ New keyword Pragma for directives

1.6 beta 9
+ FileExist function

1.6 beta 7
+ ability to make actions when TC closing

1.6 beta 6
+ added full-fledged comparison expressions
+ special functions for comparisons
+ Process plugin (working with processes)

1.6 beta 5
* fully changed plugin API
+ %AUTORUN_TCPID% constant added
+ added Windows 8 detection
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Version 2.01 has been released, it is shipped with CHM help file and contains many changes accumulated during long beta period.
totalcmd.net wrote:Version 2.0.1
- fixed MoveButton plugin with TC 8.50 beta

Version 2.0.0
+ added x64 version
+ ability to make actions when TC closing
+ added full-fledged comparison expressions
+ commands for working with registry
+ Process plugin (working with processes)
+ Sysinfo plugin (retrieve extended system info)
* fully changed plugin API
* changed help file format to HTML Help
Usul23
Junior Member
Junior Member
Posts: 3
Joined: 2014-07-07, 09:52 UTC

Helpfile not very helpful ;-(

Post by *Usul23 »

Hello MVV,

I tried using "fileexist" to check for the existence of a file using environment variables to construct the path.
For this purpose I used the conditional like

Code: Select all

IF FileExist %COMMANDER_PATH%\config\%COMPUTER_NAME%-Dirmenu.ini Then ...
Endif 
This gave me a permanent syntax error concerning the FilExist function.
Then I used the syntax variation with a variable to store the result, but that way I always get a 0 even if the file exists.

Could you please help me using it the correct way for the help-file doesn't offer much help in the error case...

Thanks
Usul
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Works ok for me:

Code: Select all

IF FileExist "%COMMANDER_PATH%\Data\1.ini" Then
	IniWrite "%COMMANDER_PATH%\Data\1.ini" "sec" "key" "yes"
Else
	IniWrite "%COMMANDER_PATH%\Data\1.ini" "sec" "key" "no"
Endif
On first TC restart I see no (because file wasn't there) but on second TC restart I see yes.

Have you tried to quote filename? It is quoted in example from help topic.
Usul23
Junior Member
Junior Member
Posts: 3
Joined: 2014-07-07, 09:52 UTC

..looks similar, but errors:

Post by *Usul23 »

Hi MVV,

works now ... I had a little typo with the FileExist .. forgot an "e".

Thanks for your help.
baiyq
Junior Member
Junior Member
Posts: 6
Joined: 2010-03-15, 08:28 UTC

Re: [WDX] Autorun Plugin: Run commands/set envvars on TC sta

Post by *baiyq »

very nice plugin. thanks a lot!

I add many portable application in autorun.cfg , but when I restart tc , many application will start another instance , I don't hope this, only one instance is enough.

plz help me! thanks again!
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

Well, I think you could use ProcessExist command to check that some of your processes was already started (some with the most unique name to prevent detections of regular PC processes, or just pass full process' path with /F option).

Example:

Code: Select all

LoadLibrary Plugins\Autorun_Process.dll

Set myFirstTool "%COMMANDER_PATH%\Tools\Tool1\tool1.exe"
ProcessExist /F alreadyRunning "%myFirstTool%"
If %alreadyRunning% = 0 Then
	ShellExec "%myFirstTool%"
	# start other tools
Endif
Or maybe even easier way:

Code: Select all

LoadLibrary Plugins\Autorun_Process.dll

ProcessCount /F numInstances "%COMMANDER_EXE%"
If %numInstances% = 1 Then
	# start all tools here
Endif
Post Reply