One of the most annoying thing of Mac is that encoding, espeically you’re living in a non-Mac world.
Mac uses UTF-8 as the default encoding for text files. But Windows uses local encoding, so it changes according to your OS language. For Chinese users, Windows uses GB2312 as the default encoding.
So usually the movie subtitle files, the song lyrics files, the plain text novel files, the code contains Chinese, which you downloaded form web sites or recieved from others usually cannot be read because of the wrong encoding.
So I really wish to have an item in my finder’s context menu that I can adjust the encoding of selected files with 1-click.
Luckily, with the help of Ruby, Automator workflow and Mac OSX service, it isn’t that hard.
So basically, OSX loads all the workflow files saved in ~/Library/Services/
, which is displayed as Context Menu in finder.
To build the service, work through the following steps:
1. To create a new service, just pick Service
in Automator’s ‘create new document’ dialog.
2. Set service input as “files and folders from any application”.
3. Run Ruby Script to transcode the files
Add a “Run Shell Script” action to execute the following ruby code, which is used to transcode the files passed to service. (For more detail about how to embed Ruby in workflow, check out Using RVMed Ruby in Mac Automator Workflow )
Make sure the input is passed as arugments to the ruby script.
|
|
4. Display a growl message when processing is done
5. Prompt user whether to keep the backup files
I use a Ask for confirmation
action to ask whether user want to keep the backup files.
The workflow will abort if user clicks “No”, make sure you updated the text on the buttons, and texts are put on right button.
6. Add script to remove backup files
Add another “Run Shell Script” aciton to execute another piece of ruby code.
|
|
7. Display notification to tell user that backup files has been deleted
TIP: The transcode ruby script requires Ruby 1.9+, but Mac OS X default provides Ruby 1.8.3, which doesn’t support encoding. To interprets workflow embedded code with ruby 1.9+, please refers to Using RVMed Ruby in Mac Automator Workflow