Has anyone successfully modified the Rename- Replace Text… script to delete text to nothing (rather than replacing with a space)? I saw a post from long ago someone wanting this without success. I know replacing text at the beginning does not replace with space(s); I have internal text that needs to be deleted in the name without replacing with spaces
Yeah, for example:
Existing Name: “2015-06-12 and other text that contains spaces”
New (desired) Name: “20150612 and other text that contains spaces”
Want to remove the dashes in the name. Current script will replace them with anything (including a blank space), but won’t allow replacing them with nothing (deletion)
The current script only works if the text to be replaced is located at the beginning or end of the name by ignoring the replacing ‘space’ character.
But when located within the name, it replaces with an actual space producing:
“2015 06 12 and other text that contains spaces”
rather than desired:
“20150612 and other text that contains spaces”
This script will prompt for a string to remove and will delete every instance of that string.
It is a lot better to not do this with AppleScript, IMO, but heres the AS version:
-- Delete characters in names
-- by korm 20150609
-- based on:
-- Replace Text in Names
-- Created by Christian Grunenberg Sat May 15 2004.
-- Copyright (c) 2004-2014. All rights reserved.
-- Based on (c) 2001 Apple, Inc.
tell application id "DNtp"
try
set this_selection to the selection
if this_selection is {} then error "Please select some contents."
set search_string to text returned of (display dialog "Enter character string to replace" default answer "" with title "Replace character string")
set od to AppleScript's text item delimiters
repeat with this_item in this_selection
set current_name to the name of this_item
if current_name contains search_string then
set AppleScript's text item delimiters to search_string
set text_items to the text items of current_name
set AppleScript's text item delimiters to od
set current_name to text_items as string
set the name of this_item to current_name
end if
set the name of this_item to current_name
end repeat
set AppleScript's text item delimiters to od
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
end try
end tell