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?
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.
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
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.
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
And if you Devonthink heroes 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.