Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thriftinkid

macrumors regular
Original poster
Mar 24, 2008
119
0
Hey guys. I want to convert all the file names within a folder to the following:

My First Movie.mov

to

my_first_movie.mov

I know you can do this easily within automator with the "make web friendly" action.

I have an automaor workflow that uses way to many programs to accomplish my goal, so I am trying to write as much as I can in applescript form. I would like to stay out of automator because I don't find it very dependable.

Does anyone know how I would do this using applescript, or do you know a shell command to use within my script?

I'm assuming you would just use the the line "do shell command...", but I'm not sure.

Thanks Guys.
 
Automator was made for stuff like this ...

Just use the Rename Finder Items workflow, choose Replace Text, search for space, replace with underscore. Save it as an app and you're done. You could do it in AppleScript but that adds a layer of complexity that just isn't worth it.

mt
 

Attachments

  • Picture 1.png
    Picture 1.png
    18.8 KB · Views: 66
Ruby Script and Applescript not being friends

Hey Guys I have the following ruby script. But when I try and run it through applescript (Which I need to to) I get one of the following two errors:

Ruby Script:

Code:
#!/usr/bin/env ruby -w

if ARGV.size != 1
  puts "USAGE: Supply a folder path to files to rename."
  exit
end

dir_path = ARGV[0]
DIR_TO_IGNORE = ['.', '..', '.DS_STORE']

(Dir.entries(dir_path) - DIR_TO_IGNORE).each do |file_name|
  begin
    file_path = "#{dir_path}#{file_name}"
    u_name = file_name.downcase.gsub(/\s/, '_')
    new_name = "#{dir_path}#{u_name}"
    File.rename(file_path, new_name)
  rescue
    puts "Error renaming: #{file_name}"
  end
end

Save Ruby as rename_files.rb to Movies folder


Code:
set thePath to ((path to movies folder as text) & "MyFolder")
do shell script "/usr/bin/ruby '/path/to/rename_files.rb' " & thePath

Error Message:


/usr/bin/ruby: No such file or directory -- /path/to/rename_files.rb (LoadError)

Code:
set thePath to quoted form of (POSIX path of ((path to movies folder as text) & Upload))
do shell script "/usr/bin/ruby '/path/to/rename_files.rb' " & thePath


Error Message:



The variable MyFolder is not defined.



Any idea why this isn't calling the ruby script.
 
I believe that:

/path/to/rename_files.rb

is a placeholder. You should replace it with the actual path of the file you want to rename.

and

:

Is there a file "MyFolder"?

mt
 
Are you literally using "/path/to/rename_files.rb" here?
Code:
set thePath to ((path to movies folder as text) & "MyFolder")
do shell script "/usr/bin/ruby '/path/to/rename_files.rb' " & thePath

If so, you need to change it to the actual path where your rename_files.rb is. As in:
Code:
set thePath to ((path to movies folder as text) & "MyFolder")
do shell script "/usr/bin/ruby '~/Movies/rename_files.rb' " & thePath
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.