Script / Smart rule possible? Convert characters in names of items and groups

Hello,

I have the problem that items or groups often contain characters (for example, / % § & …). This causes errors when synchronizing (indexed) folders with my NAS. The NAS does not support such characters in file names.

Is it possible to develop a script / a smart rule, which automatically converts incompatible characters into another character (for example, “_”) when importing?

Thanks.
Chris

What kind of NAS do you use, which filesystem does it use and how is it mounted in the Finder (e.g. via SMB, AFP or WebDAV)? A simple test using a Synology DiskStation was successful, these characters are supported.

I’m using a Synology DiskStation, filesystem is btrfs. The files are syncing with the Synology Drive client.

Thanks a lot.

Might be a limitation of the sync software. However, a smart rule executing a script could handles this. But the script would have to change the titles of the items to update the filename, e.g. like this:

on performSmartRule(theRecords)
	tell application id "DNtp"
		set od to AppleScript's text item delimiters
		repeat with theRecord in theRecords
			set theName to name of theRecord
			set theFixedName to my replaceText(theName, "§", "_")
			set theFixedName to my replaceText(theFixedName, "/", "_")
			set theFixedName to my replaceText(theFixedName, "%", "_")
			set theFixedName to my replaceText(theFixedName, "&", "_")
			if theFixedName is not equal to theName then set name of theRecord to theFixedName
		end repeat
		set AppleScript's text item delimiters to od
	end tell
end performSmartRule

on replaceText(t, s, r)
	local temp_list
	if t contains s then
		set AppleScript's text item delimiters to s
		set temp_list to text items of t
		set AppleScript's text item delimiters to r
		set t to temp_list as string
	end if
	return t
end replaceText

:sunglasses: Great!

I do not want to take your time too much, but is ist possible to shorten the name to e.g. 143 characters automatically? This seems to be a problem on Synology DS as well. :pray:

Just a minor change :slight_smile:

property pMaxLen : 143

on performSmartRule(theRecords)
	tell application id "DNtp"
		set od to AppleScript's text item delimiters
		repeat with theRecord in theRecords
			set theName to name of theRecord
			set theFixedName to my replaceText(theName, "§", "_")
			set theFixedName to my replaceText(theFixedName, "/", "_")
			set theFixedName to my replaceText(theFixedName, "%", "_")
			set theFixedName to my replaceText(theFixedName, "&", "_")
			if length of theFixedName > pMaxLen then set theFixedName to (characters 1 thru pMaxLen of theFixedName) as string
			if theFixedName is not equal to theName then set name of theRecord to theFixedName
		end repeat
		set AppleScript's text item delimiters to od
	end tell
end performSmartRule

on replaceText(t, s, r)
	local temp_list
	if t contains s then
		set AppleScript's text item delimiters to s
		set temp_list to text items of t
		set AppleScript's text item delimiters to r
		set t to temp_list as string
	end if
	return t
end replaceText

That’s really great! :star_struck: Thanks a lot!

And if you Devonthink heroes :wink: have some more time, it would be great if a smart rule could be triggered by (or after) renaming an item or a group. Maybe that’s easy to implement.

Thanks again to you and the whole team!

And if you Devonthink heroes :wink: have some more time

Who said we have any time, let alone more? Couldn’t resist :stuck_out_tongue: :laughing:

it would be great if a smart rule could be triggered by (or after) renaming an item or a group.

This sounds like a potentially dangerous idea for an automatic process.

Don’t think it’s more dangerous than other smart rules :slight_smile:

:joy: … dangerous behavior of employees at the computer forces to even more dangerous automatic processes … Thanks for the fun!