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.

3 Answers 3



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
  • Thank you so much! Just one last question: How would I jam this into Automator in such a way that it replaces my default paste? Or should I be putting this code somewhere else? Sorry, I'm very new to AS and automation in general
    – Tomulent
    Commented Jul 28, 2013 at 20:58
  • You can put it in a service to be accessed in the contextual menu. Drag the Run AppleScript action into Automator. You can also map the script to a keystroke.
    – adayzdone
    Commented Jul 28, 2013 at 23:07

Actually there is no need for Script.

Assuming you are opening the PDF files with Adobe Reader!

Coping the text (titles) containing the (:)

Selecting Save As and pasting the text.

Adobe will automatically change the (:) in to (-)

  • That's one way to do it, but it would add another step to the workflow (Save As). I have to do lot's of these renamings so that would end up slowing me down. But thanks for trying to find a less technical solution!
    – Tomulent
    Commented Jul 28, 2013 at 21:11
  • I must have missed something in your work flow as specified: You said --I have to open the file, select the title, paste it into the filename field ?? Filename field is the one it is saved as !
    – Ruskes
    Commented Jul 28, 2013 at 21:20
  • I misspoke. What I mean is that I rename the file in the finder. I can't name the file before downloading it so I do it in the finder. I guess I haven't done it your way because that would require tossing out duplicate files at the end of the batch. I'm going to do two runs, one with your solution and one with adayzdone's script and see which one is better.
    – Tomulent
    Commented Jul 28, 2013 at 21:32
  • Ok, test done. Your solution proved more efficient. Even though I have to trash the original every time, it saves me keystrokes and mouse movements
    – Tomulent
    Commented Jul 28, 2013 at 21:42
  • 1
    I marked adayzdone's answer because it specifically answered the question I was asking. I won't implement it in this case but I'm sure I'll be able to modify it to suit other needs in the future. Yours turned out to be a better solution but and if I had enough rep I would upvote it for relevance, but I think it's more appropriate to give the check mark to adayzdone.
    – Tomulent
    Commented Jul 29, 2013 at 1:21

While this is obviously an old, already answered question, it appeared as the top 'related' post for a very new question so I took a look at it without considering its age. There are some alternative approaches but I think the easiest would be to take advantage of pdf metadata and use Automator to rename the file accordingly.

This workflow takes the selected PDFs, extracts the 'Title' data and then renames the selected files.

  • Get Selected Finder Items
  • Get PDF Metadata
    • Check only 'Title' in 'Metadata To Extract'
    • Uncheck 'Write Input File Name'
  • Get Selected Finder Items
  • Rename PDF Documents

NB If the pdf does not have 'title' metadata, then the resulting file name will be — surprise — 'Untitled.pdf'. If your pdf supply has that field data consistently set then it's a non-issue but if otherwise, you could probably construct a 'run applescript' or 'run shell script' action that checks for that value and if it's non-existent, supplies an alternative — for example, by opening the pdf for you to select the title and then copy it to the clipboard and use that.

Also, if the 'title' contains a colon, then this will be converted to a '_' or '/' (rather than a hyphen). If there is a fetishistic need for a hyphen, then some additional processing could be done.

Finally, this could be turned into a Service or a Droplet if that is more convenient.

  • Always such a weird feeling when my questions from ages ago come back to my inbox. It’s like looking at baby photos. I hope someone benefits from your answer. Honestly, these days I would just spend a couple minutes making a Hazel rule and it would be automated forever.
    – Tomulent
    Commented Apr 16, 2021 at 13:35
  • Very recently, I received an 'excavator' badge. Maybe after enough time has passed, they should offer an 'archeologist' badge. As I worked on it, I considered it unlikely that this would still be part of your work but as you mention, maybe for someone else. I had a similar issue with colons in web page titles so it caught my eye when it appeared atop the list. And now it's good that it's net positive on my rep.
    – Mockman
    Commented Apr 16, 2021 at 18:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .