ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

AutoHotkey script to replace spaces in file names with underscores

(1/5) > >>

dr_andus:
I vaguely remember coming across an autohotkey script on this (?) forum for replacing spaces with underscores in file names. If this rings a bell for anyone, could you point me in the right direction? I wasn't able to find it via search. Maybe it all happened in a dream?   :-\

rjbull:
Just maybe this one?  IDEA: Standardize File Name With AHK Dialog Boxes

Does it have to be AutoHotKey?  Most of the free-standing mass file renamers will do this, if it isn't in your favourite file manager's mass renaming feature already.

dr_andus:
Just maybe this one?  IDEA: Standardize File Name With AHK Dialog Boxes
-rjbull (May 20, 2014, 04:52 PM)
--- End quote ---

Thanks for the suggestion. It looks a bit more complicated than what I was looking for.

Does it have to be AutoHotKey?  Most of the free-standing mass file renamers will do this, if it isn't in your favourite file manager's mass renaming feature already.
-rjbull (May 20, 2014, 04:52 PM)
--- End quote ---

Yes, I already use AutoHotkey, so that would be the simplest solution.

Upon second thought, this doesn't really need to be a special operation for file names specifically, a generic script would do. All I want to be able to do is copy a document's title and use it as its new file name by using a special paste operation that replaces the spaces in the title (file name) with underscores. But it's fine if it also works in any other context, not only within the save dialog box.

Also, it's not for mass renaming but just fixing individual file names. Basically I'd download articles in PDF formats, copy the titles from within the document, and paste it into the save dialog box with a special command to replace spaces (and perhaps any special disallowed characters that need be, mainly apostrophes) with underscores.

lanux128:

@dr_andus: i have a script that does that, see if you can use it.


--- Code: Autohotkey ---#Persistent#SingleInstance, Force#NoEnv SetBatchLines, -1SetWorkingDir, %A_ScriptDir%SendMode, Input ; Select the text and press Alt+v to convert space -> underscore;#d::!v::Clipboard = Send, ^cClipWait, 2If ErrorLevel{    TrayTip,, The attempt to copy text onto the clipboard failed.    Return}StringReplace, Clipboard, Clipboard, %A_SPACE%, _, UseErrorLevel   If ErrorLevel   {  TrayTip,%ErrorLevel%,%Clipboard%,,1 }Else                                    TrayTip,,%ErrorLevel%,,1            Return
usage:
1. run the script
2. select some text
3. press Alt+v

dr_andus:
lanux128, many thanks for the script! I'm having a bit of trouble with it though. As I'm using an Apple keyboard, there isn't a Win key. So I changed WIN+D to ALT+V. After that I was able to have one successful instance, but after that it wouldn't do it, even when I reload the script.

This makes me wonder if some bits of this script interfere with some other bits in my file. I don't know anything about AutoHotkey, but for example I already have this elsewhere in the file:


--- ---#Persistent  ; Keep the script running until the user exits it.
#SingleInstance force
#MaxHotkeysPerInterval 200
So I'm wondering if that somehow clashes with your


--- ---#Persistent
#SingleInstance, Force
#NoEnv
I've got loads of other scripts in the file (even for remapping my Apple keyboard's keys).

Navigation

[0] Message Index

[#] Next page

Go to full version