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

<< < (3/5) > >>

rjbull:
I'd really prefer to use AutoHotkey for this, so that the whole operation can be carried out by a series of keyboard shortcuts in one place, rather than having to switch to another software window and then back again.-dr_andus (May 22, 2014, 04:23 PM)
--- End quote ---
You don't need to switch windows with (at least) Clippy or ArsClip.  You copy the text to the clipboard in the usual way, press a hotkey you've already set for that particular action, and press Ctrl+V to paste the modified text back again.  However, it's more a low-drag solution from my point of view as I routinely run ArsClip anyway.  Before it sprouted the search-and-replace feature I used Clippy, which has a wide range of other text munging features.

lanux128:
@dr_andus: i cannot replicate the problem you face. i too run several AHK scripts (5 raw, 4 compiled) with a couple of clipboard extenders but the script i posted had no problems.

what happens if you copy-paste my script in to the Alt+W one? do you get a tray balloon like in the image below?

Spoiler


at this point, i suspect it has something to do with Win7's UAC which suppresses the script silently, instead of elevating the process.

i wonder if someone could try the script and post some feedback. @rjbull, do you fancy? :)

tomos:
I had a quick go, got an error message showing file paths with underscores added - but there is no change to focused files.
No change if I also run the Count_words script.
I see that these paths are also copied to the clipboard.



Win7 x64 / UAC on highest setting / AHK_L

dr_andus:
Thanks for all your help. I have UAC switched off. I've never seen that tray balloon pop up, but then I only managed to execute the script twice so far, and after both instances things got messed up.

I'm starting to think that the problem may have to do with some conflict with my Apple keyboard remapping. For example, I get different behaviour with clipboard related shortcuts depending on the types of shortcut keys I use. Also, when I tried to set up a hotkey for the ArsClip macro and hit Command, which is mapped as Win, it showed up as Win+CTRL. So I suspect a lot more is happening when I press certain keys than I'm able to see.

Anyway, here is my keyboard remapping script, in case anyone might be able to spot the culprit in there:


--- ---;---------------------------------
; Apple Keyboard remapping       |
;---------------------------------

; Function Keys

+F3::Send {PrintScreen}

+F7:
IfWinExist, ahk_class iTunes
ControlSend, ahk_parent, ^{LEFT} ; < previous
return

+F8::
IfWinExist, ahk_class iTunes
ControlSend, ahk_parent, {SPACE} ; play/pause toggle
return

+F9::
IfWinExist, ahk_class iTunes
ControlSend, ahk_parent, ^{RIGHT} ; > next
return

+F10::Send {Volume_Mute}
+F11::Send {Volume_Down 3}
+F12::Send {Volume_Up}

#Left::SendInput {Home}
#Right::SendInput {End}
#+Left::sendInput +{Home}
#+Right::SendInput +{End}
!Left::SendInput ^{Left}
!Right::SendInput ^{Right}
!+Left::SendInput ^+{Left}
!+Right::SendInput ^+{Right}

^Backspace::SendInput {Del}

; copy, paste, save, select all etc
#c::^c
#x::^x
#v::^v

#s::^s
#a::^a
#z::^z
#b::^b
#i::^i

; Keyboard Characters

^3::Send {Raw}#
^2::Send {Raw}@
^'::Send {Raw}"
I also have this at the top of my main AutoHotkey script (I don't know what it does. I inherited it from someone):


--- ---SetTimer,UPDATEDSCRIPT,1000
UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
SplashTextOn,,,Updated script,
Sleep,500
Reload
}
return

#Persistent  ; Keep the script running until the user exits it.
#SingleInstance force
#MaxHotkeysPerInterval 200

dr_andus:
As for ArsClip, I'm not sure what I'm doing wrong, but I tried to set up a macro for replacing spaces with underscores, but the keyboard shortcuts would not trigger most of the time, and if some combinations did, it would just replace the copied text with the macro text: " REPLACE="_"]

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version