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 automator 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.
Also, in looking at the shell script, it says puts “USAGE: Supply a folder path to files to rename.”. Does a normal applescript command work here? Such as:
puts "USAGE: ((path to movies folder as text) & MyFolder)"
The script above is a Ruby script. You cannot use ‘puts’ inside AppleScript.
You can get a POSIX path by saying
set thePath to quoted form of (POSIX path of ((path to movies folder as text) & MyFolder))
do shell script "/usr/bin/ruby '/path/to/rename_files.rb' " & thePath
I saved the “.rb” file to my desktop, and ran the following 2 scripts and got the following 2 errors:
Applescript Error:
set thePath to ((path to movies folder as text) & "MyFolder")
do shell script "/usr/bin/ruby '/path/to/rename_files.rb' " & thePath
/usr/bin/ruby: No such file or directory – /path/to/rename_files.rb (LoadError)
and
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
Ok, change the /path/to/rename_files.rb to the actual path. This is just a place holder.
set rubyFile to quoted form of POSIX path of ((path to desktop as Unicode text) & "rename_files.rb")
do shell script "/usr/bin/ruby " & rubyFile & space & thePath
Make sure to use quoted form of POSIX path of when creating the path. This is the type of path the Shell uses.
I ran the following script and got the following return:
set thePath to quoted form of (POSIX path of ((path to movies folder as text) & "myFolder"))
set rubyFile to quoted form of POSIX path of ((path to desktop as Unicode text) & "rename_files.rb")
do shell script "/usr/bin/ruby " & rubyFile & space & thePath
Well my genious just realized I didn’t put a file in the folder. So I place one in there and ran it again. But got a similar return:
set thePath to quoted form of (POSIX path of ((path to movies folder as Unicode text) & "MyFolder"))
set rubyFile to quoted form of POSIX path of ((path to desktop as Unicode text) & "rename_files.rb")
do shell script "/usr/bin/ruby " & rubyFile & space & thePath
Returned:
“Error renaming: .DS_Store
Error renaming: My First Movie.mov”
Ok, did that. I’m a little closer. It got rid of the “.ds” error, but the second error still remains. I know nothing of ruby. I copied your ruby script into text editor and saved it out under your file name. Is that the correct way to do that, or should I be saving that file in a different manner?
set thePath to quoted form of (POSIX path of ((path to movies folder as Unicode text) & "myFolder"))
set rubyFile to quoted form of POSIX path of ((path to desktop as Unicode text) & "rename_files.rb")
do shell script "/usr/bin/ruby " & rubyFile & space & thePath
That is correct as long as you are using a text editor like TextMate, BBEdit, TextRangler, etc. If you are using TextEdit make sure that you turn the document into a Plain Text doc. Format->Make Plain Text. If it is already plain text then the menu will display Format->Make Rich Text.
set thePath to quoted form of (POSIX path of ((path to movies folder as Unicode text) & "myFolder"))
set rubyFile to quoted form of POSIX path of ((path to desktop as Unicode text) & "rename_files.rb")
do shell script "/usr/bin/ruby " & rubyFile & space & thePath
Returned:
“here
Error renaming: .
here
Error renaming: …
here
Error renaming: .DS_Store
here
Error renaming: My First Movie.mov”