Need help to add vbscript in button

I write button to launch rename preset but now i want to add the script into button, but it doesn't work...

<?xml version="1.0"?> <button backcol="none" display="both" separate="yes" textcol="none"> <label>Au début/fin</label> <tip>Insérer au début/fin</tip> <icon1>#statusbar</icon1> <function type="normal"> <instruction>@nodeselect </instruction> <instruction /> <instruction>@script vbscript </instruction> <instruction>Option Explicit </instruction> <instruction /> <instruction>Dim TexteD, TexteF </instruction> <instruction /> <instruction>Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName ) </instruction> <instruction /> <instruction> If Len(TexteD) = 0 Then </instruction> <instruction> TexteD = inputbox (&quot;Insert at left...&quot;,&quot;Insert&quot;,&quot;&lt; Nothing &gt;&quot;) </instruction> <instruction> If TexteD = &quot;&quot; Then Exit Function</instruction> <instruction> End if </instruction> <instruction> If Len(TexteF) = 0 Then </instruction> <instruction> TexteF = inputbox (&quot;Insert at right...&quot;,&quot;Insert&quot;,&quot;&lt; Nothing &gt;&quot;) </instruction> <instruction> If TexteF = &quot;&quot; Then Exit Function</instruction> <instruction> End if </instruction> <instruction> </instruction> <instruction> Dim Ext, NomFichier, DebutFichier, FinFichier</instruction> <instruction> </instruction> <instruction> If fIsFolder = False Then &apos;if folder, extension = nothing</instruction> <instruction> Ext = Right (strFileName, Len(strFileName) - (InStrRev(strFileName, &quot;.&quot;) - 1))</instruction> <instruction> Else</instruction> <instruction> Ext = &quot;&quot;</instruction> <instruction> End if</instruction> <instruction> </instruction> <instruction> NomFichier = Left (strFileName, Len(strFileName) - Len(ext))</instruction> <instruction> strNewName = TexteD &amp; NomFichier &amp; TexteF &amp; Ext</instruction> <instruction> strNewName = replace(strNewName, &quot;&lt; Nothing &gt;&quot;, &quot;&quot;)</instruction> <instruction /> <instruction>End Function</instruction> </function> </button>

You just need to add a Rename command to the button. (Without any command, the script doesn't do anything on its own.)

Rename PATTERN * TO * is probably what you want, like this:


Of course... Thanks Leo...

Other question...
I want button to launch scripts with @keydown so...

[code]@nodeselect
Rename PATTERN * to *

@keydown:none
@script vbscript
Function ...
'my script
End function

@keydown:shift
@script vbscript
Function ...
'my another script
End Function[/code]

But button failed, error with @keydown:shift. :frowning:

Yeah that won't work, but you should be able to put the scripts in a user command and then call them from within the @keydown sections.

Or there's probably some way of testing the qualifier key state in the actual vbscript code; then you could do it all in the one script.

As well as Jon's user-commands suggestion, an alternative is to put the scripts into rename presets, then use @keydown sections where each one specifies a different rename preset name.

ok but i don't like user commamd because i would like a "portable" button (without another extra file).
i try to find something to combine my scripts or to catch keys qualifier...

here is my button

<?xml version="1.0"?> <button backcol="none" display="both" textcol="none"> <label>A la position</label> <tip>Insérer à la position (maj en partant de la fin)</tip> <icon1>#statusbar</icon1> <function type="normal"> <instruction>@nodeselect </instruction> <instruction>rename pattern * to *</instruction> <instruction /> <instruction>@keydown:none</instruction> <instruction /> <instruction>@script vbscript </instruction> <instruction>Option Explicit </instruction> <instruction /> <instruction>Dim Position, Texte </instruction> <instruction>Dopus.OutputString &quot;Script: Insérer à la position (en partant du début) - Ecrit par: Albator V&quot;</instruction> <instruction /> <instruction>Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName ) </instruction> <instruction /> <instruction>If Len(Position) = 0 Then </instruction> <instruction> Position = inputbox (&quot;Position du texte à insérer en partant du début... ( texte après la position )&quot;,&quot;Position du texte à insérer&quot;,0) </instruction> <instruction> if Position = &quot;&quot; then exit function</instruction> <instruction>End if </instruction> <instruction>If Len(Texte) = 0 Then </instruction> <instruction> Texte = inputbox (&quot;Texte à insérer.&quot;,&quot;Texte à insérer&quot;) </instruction> <instruction> If Texte = &quot;&quot; Then Exit Function</instruction> <instruction>End if </instruction> <instruction /> <instruction>Dim Ext, NomFichier, DebutFichier, FinFichier</instruction> <instruction /> <instruction>If fIsFolder = False Then &apos;si c&apos;est un dossier extension = rien</instruction> <instruction> Ext = Right (strFileName, Len(strFileName) - (InStrRev(strFileName, &quot;.&quot;) - 1))</instruction> <instruction>Else</instruction> <instruction> Ext = &quot;&quot;</instruction> <instruction>End if</instruction> <instruction /> <instruction>NomFichier = Left (strFileName, Len(strFileName) - Len(ext))</instruction> <instruction>DebutFichier = Left (NomFichier, Position)</instruction> <instruction>FinFichier = Right (NomFichier, Len(NomFichier) - Position)</instruction> <instruction /> <instruction>strNewName = DebutFichier &amp; Texte &amp; FinFichier &amp; Ext</instruction> <instruction /> <instruction>End Function </instruction> <instruction /> <instruction>@keydown:shift</instruction> <instruction /> <instruction>@script vbscript </instruction> <instruction>Option Explicit </instruction> <instruction /> <instruction>Dim Position, Texte </instruction> <instruction>Dopus.OutputString &quot;Script: Insérer à la position (en partant de la fin) - Ecrit par: Albator V&quot;</instruction> <instruction /> <instruction>Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName ) </instruction> <instruction /> <instruction>If Len(Position) = 0 Then </instruction> <instruction> Position = inputbox (&quot;Position du texte à insérer en partant de la fin... ( texte avant la position )&quot;,&quot;Position du texte à insérer&quot;,0) </instruction> <instruction> if Position = &quot;&quot; then exit function</instruction> <instruction>End if </instruction> <instruction>If Len(Texte) = 0 Then </instruction> <instruction> Texte = inputbox (&quot;Texte à insérer.&quot;,&quot;Texte à insérer&quot;) </instruction> <instruction> If Texte = &quot;&quot; Then Exit Function</instruction> <instruction>End if </instruction> <instruction /> <instruction>Dim Ext, NomFichier, DebutFichier, FinFichier</instruction> <instruction /> <instruction>If fIsFolder = False Then &apos;si c&apos;est un dossier extension = rien</instruction> <instruction> Ext = Right (strFileName, Len(strFileName) - (InStrRev(strFileName, &quot;.&quot;) - 1))</instruction> <instruction>Else</instruction> <instruction> Ext = &quot;&quot;</instruction> <instruction>End if</instruction> <instruction /> <instruction>NomFichier = Left (strFileName, Len(strFileName) - Len(ext))</instruction> <instruction>DebutFichier = Left (NomFichier, Len(NomFichier) - Position)</instruction> <instruction>FinFichier = Right (NomFichier, Position)</instruction> <instruction /> <instruction>strNewName = DebutFichier &amp; Texte &amp; FinFichier &amp; Ext</instruction> <instruction /> <instruction>End Function </instruction> </function> </button>

You can do it like this:

[code]@nodeselect

@keydown:none
Rename PATTERN * TO="NONE"

@keydown:shift
Rename PATTERN * TO="SHIFT"

@keydown:common

@script vbscript
Option Explicit

Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )

Dim keyName
keyName = strNewName

' Put strNewName back to normal (no rename unless we change it ourselves).
strNewName = strFileName

If (keyName = "NONE") Then

	inputbox("I'm called with none")

ElseIf (keyName = "SHIFT") Then

	inputbox("I'm called with shift")

Else

	inputBox("Error!")

End If

End Function[/code]

Watch out since if the script is invalid, and doesn't run at all, then the command will rename the selected file to "NONE" or "SHIFT".

Excellent, many thanks again...
But if I select more than one file, my dialog appear for each files

[code]@nodeselect

@keydown:none
Rename PATTERN * TO="NONE"

@keydown:shift
Rename PATTERN * TO="SHIFT"

@keydown:common

@script vbscript
Option Explicit

Function Rename_GetNewName ( strFileName, strFilePath, fIsFolder, strOldName, ByRef strNewName )
Dim Position, Texte, Ext, NomFichier, DebutFichier, FinFichier, keyName

keyName = strNewName
strNewName = strFileName

If (keyName = "NONE") Then

Dopus.OutputString "Script: Insérer à la position (en partant du début) - Ecrit par: Albator V"

If Len(Position) = 0 Then 
   Position = inputbox ("Position du texte à insérer en partant du début...     ( texte après la position )","Position du texte à insérer",0) 
   if Position = "" then exit function
End if 
If Len(Texte) = 0 Then 
   Texte = inputbox ("Texte à insérer.","Texte à insérer") 
   If Texte = "" Then Exit Function
End if 

If fIsFolder = False Then 'si c'est un dossier extension = rien
    Ext = Right (strFileName, Len(strFileName) - (InStrRev(strFileName, ".") - 1))
Else
    Ext = ""
End if

NomFichier = Left (strFileName, Len(strFileName) - Len(ext))
DebutFichier = Left (NomFichier, Position)
FinFichier = Right (NomFichier, Len(NomFichier) - Position)

strNewName = DebutFichier & Texte & FinFichier & Ext

ElseIf (keyName = "SHIFT") Then

Dopus.OutputString "Script: Insérer à la position (en partant de la fin) - Ecrit par: Albator V"

If Len(Position) = 0 Then 
   Position = inputbox ("Position du texte à insérer en partant de la fin...       ( texte avant la position )","Position du texte à insérer",0) 
   if Position = "" then exit function
End if 
If Len(Texte) = 0 Then 
   Texte = inputbox ("Texte à insérer.","Texte à insérer") 
   If Texte = "" Then Exit Function
End if 

If fIsFolder = False Then 'si c'est un dossier extension = rien
    Ext = Right (strFileName, Len(strFileName) - (InStrRev(strFileName, ".") - 1))
Else
    Ext = ""
End if

NomFichier = Left (strFileName, Len(strFileName) - Len(ext))
DebutFichier = Left (NomFichier, Len(NomFichier) - Position)
FinFichier = Right (NomFichier, Position)

strNewName = DebutFichier & Texte & FinFichier & Ext

Else

  inputBox("Error!")

End If

End Function
[/code]

So make some global (to the script) variable(s) that you can use to store things in.

If you 'dim' a variable before the 'Function' line, it will persist between each run of the function. (It'll still go away once the whole command completes.)

It's perfect, thanks...