GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Command: RenameFromClipboard


#1

RenameFromClipboard - a script command, which renames selected items by fetching text/item-names from the clipboard.

This can be very handy in case you want to rename a bunch of mp3 files, for which you already have a beautyful list of names (from an online source maybe). Another use case is updating a lot of files and folder names from a similar folder containing basically the same but differently named items.

Features:

  • detects multiline clipboard content and takes care of different line endings (CR vs. CR+LF etc.)
  • validates and shapes the clipboard content before it’s used to rename items (not idiotproof yet, so don’t use binary code for renaming o)
  • warns you if the number of selected items does not match the number of items in the clipboard
  • supports following placeholders to increase flexibility, moving of files is a usecase for that e.g.
    [ul]
    [li]%item.realpath%", %item.name%", %item.name_stem%", %item.path%", %item.ext%"[/li]
    [li]%item.new_realpath%, %item.new_name%", %item.new_path%, %item.new_ext%"[/li]
    [li]The default operation using these is Rename FROM="%item.realpath%" TO="%item.new_name%"[/li][/ul]
  • can run multiple commands (default is “Rename” only, edit script config or use COMMANDS param to set additonal params and add commands)
  • you can use plain-text directly or files and folders currently in the clipboard (these will be converted by DO to paths and names automatically)
  • safemode for testing and watching results on the console

    Parameters:
  • QUIET (avoid confirmation if number of selected items does not match number of items in clipboard)
  • DESELECT (deselect renamed items)
  • SAFEMODE (do not run any operation, for testing and previewing actions on the console)
  • COMMANDS (any dopus commands to replace/change the default rename operation, use “\n” to separate them here, param must be last)

    Demo:
    Crappy filenames in dopus:


    Nice file names in editor (copied to clipboard):


    Nice file names in DOpus after selecting the crappy mess and running “RenameFromClipboard”:


    Installation:
    To install the command, download the *.js.txt file below and drag it to Preferences / Toolbars / Scripts.
    Create a button or hotkey with the command “RenameFromClipboard” and it’s ready to go with the defaults.
    Select and copy text or files/folders from any place. Select the items to rename in dopus and eventually use your new button/menu entry.

    Have fun with it, I hope it’s useful for somebody. Bug reports and suggestions are welcome of course! o)
    cya, tbone

    Download:
    [ul][li]Latest:[/li]
    [li]v0.3 / 2015.10.01 - added placeholder %item.new_name_stem%
    Command.Item_RenameFromClipboard.js.txt (26 KB)
    [/li]
    [li]v0.2.2 - prepared to support updates/scriptwizard:
    Command.Item_RenameFromClipboard.js.txt (9.76 KB)
    [/li]
    [li]v0.2.1 - performance gain by reusing the command object for all rename operations:
    Command.Item_RenameFromClipboard.js.txt (8.87 KB)[/li][/ul]

Custom Context Menu commands: YOUR favorites?
Match file name.mp3 from .txt
Rename files from clipboard
My Dark Color Theme (Opus 12 [VERSION 3] update)
#2

Hi tbone,

thanks for the script! I have two suggestions (which I’m going to add to my version, but I thought they might be interesting for others):

a) In the error message, include the number of items:

b) Add a new parameter ‘KEEPEXT’ or similar that enables renaming of only the name stem, ignoring the extension. I realize that can probably be achieved by changing the COMMANDS parameter, but it might be useful to do it locally just for one button, as an addition to the global configuration.

MartO


#3

Hi Mart! o)

Point a): That’s part of what I use currently, valid point! o) Will upload that version, it fixes some smaller things as well (doublequote issues e.g.)
Point b): There is a commandline param “COMMANDS” as well, so you can have that “KEEPEXT” way of renaming locally, by using this command:

But I agree, I (also?) got into the situation where I accidentally got rid of my file extensions.
Maybe some auto-detection wether to take care for the extension automatically would be a good idea too, thanks for your thoughts! o)


#4

That’s an excellent idea: For files (not for dirs) check if the names in the clipboad have an extension and if not, use the original one.
Of course, if the names contain dots that are independent of the extension, it would still go wrong. Hmmm…

Yes, I understood about the commandline param COMMANDS but I didn’t think it practical to repeat the whole configuration in my local command, particularly if I might want to change the ‘central’ configuration later. On the other hand, perhaps that’s not a very likely scenario anyway and for me the better solution would be to always configure COMMANDS locally.


#5

Well, I don’t know either regarding local vs. global. I guess that’s the cruel thing about having choices! o)


#6

Does your script target scripting illiterates as well? I attempt to do that with my (not-yet-published) scripts, but of course ymmv.
Anyway, in that case the current way of configuring COMMAND is quite an obstacle anyway, isn’t it? A simple KEEPEXT is much easier to understand…
Yes, always those choices… :wink:


#7

What do you mean with “does your script target scripting illiterates”? Do you mean users not experienced with scripting?
And what do you attempt to do with your scripts? Sorry, I have difficulties understand these sentences. o)

Yes I agree, but to make it really universal we’d need KEEPFILEEXT, USECLIPEXT, AUTOEXT (default) and an additional optional requester to ask what mode to use, because you will not have 3 buttons prepared for each, right? o)


#8

Yes, that’s exactly what I meant!

I attempt to make them usable for non-experienced users. Oh, and in case that sounded strange: ‘ymmv’ means ‘your mileage may vary’ or in other words: Your expierence and opinions are probably different from mine! :smiley:
Somehow I feel this would be easier in German, wouldn’t it…? :wink:

…and I’m sure the next user will have entirely differnt wishes. This could easily become a major project for you! I hope you don’t have any other plans for the weekend?! :wink:
Well, luckily, I find myself increasingly able to write my own scripts or to adapt yours to my needs! DOpus really is a great tool!


#9

Updated to v0.2

  • trim clipboard items from text data
  • filter double quotes
  • show number of selected/clipboard items in “nomatch” popup
  • usage of confighelper for easier maintenance
  • config item descriptions added (including all supported variables)

@Mart
I was unsure on how to interpret your question, I guess mainly because I already try to be novice user friendly. o) I mean I mostly add params and config switches where sensible, to allow for easy customizations without fireing up the editor. I also try to be descriptive and give examples on the usage. But some basic DO knowlegde must still be given in order to make use of a script command. I’m curious to see your approach on novice user friendlyness. I will ask my mom to run your scripts, ok? o)


#10

Hi tbone,
I’m sorry, I didn’t mean to critisize you at all! In fact, I think it’s pretty great what you’re doing here in the forum and your scripts have been very helpful for me. They are a lot more user friendly than some of the other stuff I’ve seen.

All I wanted to know was your opinion on the same dilemma that I seem to be facing: What’s more important, a universally usable, highly configurable script - or one that’s simple to understand?

Any serious DOpus user needs to spend quite some time learning and experimenting. But I believe there’s still a big difference between users who know how to set up all the preferences they need and how to work with DOpus commands (built-in or added by scripts) and users who actually know how to program their own scripts. (Obviously I don’t know which category your mom falls in… :wink:)

One of the things I’m working on is a script that lets you select a file and then automatically selects all other files that share the same metadata, e.g. the same image size or the same mp3 artist. I want it to be flexible but simple to configure - and I find that very difficult. It’s hardly possible to set up a button for a particular metadata object property without consulting the scripting reference first - which is exactly what I’d like to avoid.:confused: So I’m not saying I have a solution at all - I wish I did! :slight_smile:

I’ll have a look at your new version tomorrow; thanks for the upload!
MartO


#11

Your welcome Mart, I don’t feel bashed, so don’t worry! o) My primary opinion on usability and accessibility is, that something should match its environment. DO is a complex masterpiece, you hardly ever get to know all of its options and features, but it does provide good documentation and some sensible ways to configure its appearance and behaviour. Anything that integrates or adds to it, should match that standard.

I think the KEEPEXT behaviour is a perfect example - the script didn’t need to be modified to make it work and it also matches how you customize things in DO - by simply modifying the command to run.

Regarding your metadata auto selector I’d say: Provide a handful of examples to get your users to understand the idea behind and just provide the link to the reference. I’d presume this is much easier for everyone than providing an obscure set/amount of prebuilt-buttons and… matches how things work in DO! o) Sticking to well known patterns is a way to get people understand quickly, inventing another wheel not always required. Nice idea btw! o)


#12

Thanks for the great script

I use Notepad++ to edit names all the time, added your script command to my context menu “Special Renaming” sub-menu.
A bit slow though, can you make it faster?


#13

Thanks for your feedback! o) What’s it exactly that’s so slow?


#14

The renaming of course, it takes 15 seconds to rename 200 items.


#15

15 secs for 200 items sounds slow indeed, maybe things get quicker if you move the lines…
…out of the outer for-loop in RenameSelectedItemsFromClipboard(). All rename commands then will be executed in a batch fashion.
(Edited to keep thread compact)


#16

I’m not familiar with the script language your using, but I’m a coder in a different language.
I edited your code a little and this seems to work just fine…

[code block removed as you can now get the change from the updated script in the main post]

The following line needed to be moved out too…

I wonder why you executed the actions one at a time?!


#17

Sorry for not mentioning the other needed change, but you are skilled it seems. o) Is it any faster with that batch mode now?

I guess because the script hasn’t reached a major version yet, so code isn’t necessarily fine-tuned to the max. o)


#18

Updated to v0.2.1

  • performance gain by reusing the command object for all rename operations (28 vs. 4secs = 700% speed increase for 200 files on my AMD quad idling at 1Ghz)

I did not expect such a speed-increase with this little tweak, good to know for upcoming scripting projects - you live and learn! o)
Thank you tuseday for being unsatisfied! o) (Please edit your post and remove any code to keep thread/posts compact, thanks!)


#19

I installed the script and it’s excellent. How do I go about modifying the script so that I can change the names of multiple files to the same name with sequential numbers? Example: change the following three file names, “stupid” “dumb” “ugly” using the word Smart (from the clipboard) in order to change to Smart 01, Smart 02, Smart 03. etc. Thank you for writing this script. It’s quite useful already.


#20

Unfortunately, this command can’t do that, but you can use the builtin rename tool/command if I understood you correctly, it has support for sequential numbering. In case you need detailed help on this, I suggest you open a new thread in the general support section.