# Automator script to remove text from file names?



## freaky (Jun 12, 2007)

I haven't used Automater before and am interested in learning more about it. Can someone tell me to go about using it so I can run a script on an entire directory and remove "_SOMETHING" from each file that it's located in?


----------



## barhar (Jun 13, 2007)

'I haven't used Automater before and am interested in learning more about it.' - 'Automator for AppleScripters', 'Guides: Apple Applications, Automator', 'Google'.

'Can someone tell me to go about using it so I can run a script on an entire directory and remove "_SOMETHING" from each file that it's located in?' - ...

01. (Library) 'Finder', (Action) 'Ask for Finder Items', [(optional) Change 'Prompt:' string].
02. (Library) 'Finder', (Action) 'Get Folder Contents', [(optional) 'Repeat for each subfolder found'].
03. (Library) 'Automator', (Action) 'Run AppleScript', [Replace contents of module / panel with (1)]

(1) - ...

on run {input, parameters}

repeat with i in input

set FREF to open for access i with write permission
set tText to read FREF
--
-- Your code to locate and filter out "_SOMETHING" here. 
-- The following 'write' line assumes the (searched and modified contents') variable will remain 'tText'.
--
set eof FREF to 0
write tText to FREF
close access FREF

end repeat

return input
end run

-----     -----     -----     -----

AppleScript alternative:

set tFolder to choose folder with prompt "Select desired folder: " default location (path to desktop from user domain) without multiple selections allowed
set folder_Contents to list folder tFolder without invisibles

repeat with i in folder_Contents

set FREF to open for access (((tFolder as string) & i) as alias) with write permission
set tText to read FREF
--
-- Your code to locate and filter out "_SOMETHING" here. 
-- The following 'write' line assumes the (searched and modified contents') variable will remain 'tText'.
--
set eof FREF to 0
write tText to FREF
close access FREF

end repeat


----------



## freaky (Jun 13, 2007)

Thanks!

Is there anyway to make the Applescript so it will add a link to the script somewhere in the file menu like Applescripts in iTunes?

I would like to be in the current directory then go up to the file menu and click the script and have it remove the specified characters from the current directory.


----------

