c.g.yogi wrote:
Yes, I know automator can do it, but I need a script. Here's the thing: I need a script to attach to a ChronSync document, so that as ChronoSync syncs folders to it's destination it will also run a script to rename the folders automatically. So I don't have to go back in and do it manually using automator. The thing is, the files that need renaming end up in subfolders, so if I used a folder action to attach to the root level folder, it would have to drill down and apply the filename changed to all files within all subfolders.
Anyone?? Thanks for the help!
That Automator is a Folder Action.
Anyway, here's a bash script:
#!/bin/bash
for f in ~/Desktop/untitled\ folder/*
do
path=${f%/*}
basename=${f##*/}
name=${basename%.*}
ext=${f##*.}
name=${name//_/-}
mv "$f" "$path/$name.$ext"
done
To use in Applescript, just use do shell script
You can adapt this for a Folder Action
See also: http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html
A sub-routine for replacing characters in strings:
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars