Script or workflow to modify find and replace text in clipboard

applescriptautomatorcommand line

I need give unique names to many, many files as part of my job. I download dozens of PDFs from a research database which all come with the same name (date of download). I have to open the file, select the title, paste it into the filename field, and then go in and manually remove the colon and replace it with a dash.

That last part is really what's killing me since basically every file I download has a colon in the title that I want to paste! What I want is something that will modify the contents of my clipboard so I can just paste it into the naming field without having to manually replace the colon.

In short, I want any ":" in my clipboard to change to a "-" before I paste it.

Best Answer

Try:

set myText to the clipboard as «class utf8»
set {TID, text item delimiters} to {text item delimiters, ":"}
set myText to text items of myText
set AppleScript's text item delimiters to "-"
set the clipboard to myText as text
set text item delimiters to TID
tell application "System Events" to keystroke "v" using command down