Renaming: How do I remove a certain number of characters?

How do I remove a certain number of characters from the beginning/end of a file name within DEVONthink? I Haven’t found any script in the scripts menu that could do this. So if anybody could help me with some AppleScript or RegEX code that would be very helpful.

Please post what the name is (and if it’s consistently conforming) and the expected output.

e. g. change “filename” and “namefile” to “filen” and “namef” by removing three characters from the end of each …

Is this supposed to preserve the file extension too?

Is this something you’re trying to learn to script or something you’ve been tasked with?

Do you have the “Replace Text…” script in the Scripts > Rename menu? Does what you’re looking for – and of course you can modify it, as a starting point, if you want to play more.

i have that script installed, however it doesn’t let me replace with “blank” text … the button is greyed out …

yes, file extension should be preserved

i’m only ably to make some “trial and error” modifying of an existing applescript, but so far i didn’t have any success with the existing “Replace Text…” script that korm mentioned … if you could give me a hint, that would help …

Your example didn’t have blanks. Sorry for the suggestion.

Use the Regex script from the Support Assistant, then.

indeed … but if it had been like

ABC_file.ext
DEF_file.ext

and i wanted to change these to ABC.ext and DEF.ext, the “Replace text” script wouldn’t work either …

that’s what i thought of … but i failed, as i don’t have any idea about regex … this is why i posted here …

Sorry to be dense, but your example has underscores.

With the Replace Text script I can replace the string " file.txt" (no quotes)

in


single file.txt

and get


single.txt

You probably have non-Unicode characters in your strings. Not knowing which characters we’re dealing with is an impediment. But these can be addressed with advance regex techniques. Which is covered in numerous tuts on the web.

but you cannot replace “file” in ABCfile.txt and DEFfile.txt with no text, so that you get ABC.txt and DEF.txt … the replace script doesn’t allow this …

It would be helpful if you provided real examples of filenames that would be encountered.

Yes you can. Tell the first dialog box to replace “file.txt” and the second replace-with dialog is “.txt” — this has the result you described in the quoted post.

Think differently?

i have dtpo set to not show the file extension, so this doesn’t work either …

Then why then do all the examples posted so far include the extension? Very confusing.