I am a real newbee at this.
I am trying to invoke a RENAME command with a PRESET and it should invoke the Rename_GetNewName2 function.
But I either get an error or nothing. What is wrong in my code below?
I have saved the RENAME command Preset as "Slides" with script mode checked, type = Standard Rename.
Should the two text boxes at the top, Old Name and New Name be blank when I save the Prreset?
As can be seen, the Function will be reworked eventually to allow a new piece of text to be entered manually.
##########################
Rename PRESET=Slides
@script vbscript
Option Explicit
Function Rename_GetNewName2 ( strFileName, strFilePath, _
fIsFolder, strOldName, strNewName )
' Add script code here
dim NewText
'NewText = InputBox("Enter new text:")
Rename_GetNewName2 = mid(strOldName,1,7) + " " + "WOW" + mid(strOldName,8,4))
End Function
########################
There are two ways to run rename scripts via buttons, depending on where you want the script to be defined:
[ol][li]Reference a Rename Preset:
If you have the script saved in a rename preset then your button can simply reference the preset. If the preset is called Multi-RegExp then the button would look like this:
Rename PRESET="Multi-RegExp"
[/li]
[li]Everything in the Button:
If you only want to run the script from a button, and don't want it cluttering up your list of rename presets, then you can put everything including the script into your button:
Hi Leo, Thanks for your input. I have succeeded in getting the function to work using the Rename PRESET = "Slides" on the Context Menu item.
Here is my current code:
@script vbscript
Option Explicit
Function Rename_GetNewName2( strFileName, strFilePath, fIsFolder, strOldName, strNewName )
' Add script code here
dim NewText
NewText = InputBox("Enter new text:")
Rename_GetNewName2 = mid(strFileName,1,7) + " " + NewText + mid(strFileName,8,4)
End Function
One problem occurs. When I use it, it insists on entering and stopping on the Textbox for Newname.
I want it to proceed on and just prompt for the user input. What am I missing?
Thanks
I'm not sure what you expect to happen here - the script stops and prompts for input, because that's what you've told it to do. How else can it get the input for NewText ?
Thanks Steve and Leo.
I explained it poorly I guess.
The script is stopping twice; once when it opens the whole RENAME dialogue edit box with Old Name: and New Name: at the very top and all the check boxes such as case sensitive & script mode etc.( that's the unwanted one) When this happens the cursor is situated at New Name: textbox which is blank and I only need to hit ENTER to continue but that is a really unnecessary pain.
and then again at the NewText prompt which I have coded( that's the desired one).
Is there some control command needed just above the line "@script vbscript"?
Or, is there other check boxes needed to be checked? I only have checked "script mode".
The Rename dialog will appear if the preset (and/or the button) doesn't specify an old and new name. In other words, if the old or new name fields are missing, Opus will prompt you for them.
If you set the preset to use:
Old Name: *
New Name: *
Type: Standard Rename
and then re-save the preset, you should no longer see the rename dialog. The new name fed to the script for each file will be the same as the old name, and the script can then modify that new name as it wishes.