PDA

View Full Version : Automator Tips (Batch Rename, Batch Delete)


flip
Apr 19, 2006, 08:11 PM
How about some Automator tips?

Here's a workflow to batch rename the Path Finder selection from the contextual menu.

1. Launch Automator and create a new workflow (File > New).
2. In the Library column, select "Automator".
3. In the Action column, double-click on "Run AppleScript".
4. Set the script to:
on run {input, parameters}
tell application "Path Finder"
set a_list to selection
set input to {}
repeat with a_ref in a_list
set a_path to POSIX path of a_ref
tell me to set a_file to POSIX file a_path
set input to input & {a_file}
end repeat
end tell
return input
end run
(Make sure it compiles by clicking on the hammer icon.)
5. In the Library column select "Finder".
6. In the Action column double-click on "Rename Finder Items" (answer No when you're prompted about duplicating the files first).
7. Use the popup menus to define the default renaming method (you'll be able to change it at run time).
8. Check the Show Action When Run checkbox under Options to be prompted when the workflow runs.
9. Save the workflow as Plug-in (File > Save As Plug-in).
10 Call it something like "Batch Rename Path Finder Selection", and make sure "Finder" is selected in the second pop-up.

That's it. If PF is set to "Append Finder contextual menu items" (from the Contextual menu preferences), you'll find your new workflow in the Automator submenu of the contextual menu. Select several files or folders in PF, use this new command, and a dialog allowing you to define how to rename the selected items will pop up.

Important

This workflow requires the Finder. If it's not running, it will be launched (assuming you didn't completely replace it with PF, in which case you're probably out of luck). If you want the Finder to quit again when the workflow is done running, just add another "Run AppleScript" action at the end of the workflow, and set its script to 'tell application "Finder" to quit'.

Enjoy!

me
Dec 16, 2006, 03:02 PM
for anyone that needs it:

I need to remove several files on a regular basic. These files have different names but all have similar prefixes or suffixes.

I made this automator workflow and access it via my PF contextual menu.

note: just copy and paste the code below into a single "applescript" automator action:



on run {input, parameters}

tell application "Path Finder"
activate
set selection_list to selection
repeat with one_item in selection_list
end repeat

set thePath to the POSIX path of one_item as rich text
set theName to the name of one_item

do shell script "rm -f " & thePath & "/xxx*"
do shell script "rm -f " & thePath & "/yyy*"
do shell script "rm -f " & thePath & "/zzz*"

end tell

end run



not sure if you need to be "rich text" but this should help people out. Right clicking and doing this all within PF will save me minutes each day and will end up saving my lots each year.


I click on the folder in PF when i launch this. If anyone can post how I can get the name of the folder the file is in I would be most appreciate as I would love to right click IN a folder rather then ON a folder since it is a larger mouse click area.

thanks for the posters that put up sample applescript in this thread.

*cocoa*
Sep 25, 2007, 05:16 AM
"This workflow requires the Finder. If it's not running, it will be launched (assuming you didn't completely replace it with PF, in which case you're probably out of luck)"

no bad, just thanks for this.. ;)