Jump to content

How to make these case converter Perl scripts work in Alfred.


Recommended Posts

Here is my problem. I modify a lot of strings cases these last days (ie Lower case to uppercase "my_file" to  "MY_FILE").

After some research, I found I could use these TextExpander perl scripts (here)  to solve the problem.

But I believed Alfred could make it faster, better, smoother.

 

What I want to do is select the name of my file, hit a hotkey, see the name of my file converted to uppercase/lowercase/sentence case...

 

I tried to create a workflow with a "Selection in OSX" and a "Run Script" command. But it doesn't work. I should say, I couldn't make it work...

I thought copying these perl script in a run script action would be enough.

 

Here are the for Perl scripts I am referring to :

 

1°) Paste clipboard to lower Case

#!/usr/bin/perl -w
 
#Initialise
use strict;
my($text);
 
#Get the text from the clipboard
$text =`pbpaste`;
 
#Output the text as lowercase
print "\L$text";

2°)  Paste clipboard to Upper Case

#!/usr/bin/perl -w
 
#Initialise
use strict;
my($text);
 
#Get the text from the clipboard
$text =`pbpaste`;
 
#Output the text as uppercase
print "\U$text";  

3°)  Paste clipboard to Sentence Case

#!/usr/bin/perl -w
 
#Initialise
use strict;
my($text);
 
#Get the text from the clipboard
$text =`pbpaste`;
 
#Convert the text to lower case
$text ="\L$text";
 
#Convert the first character of each sentence to upper case
$text =~ s/(^\w|\.\s+\w)/\U$1\E/g;
 
#Output the text
print $text; 

4°)  Paste clipboard to Title/Proper Case

#!/usr/bin/perl -w
 
#Initialise
use strict;
my($text);
 
#Get the text from the clipboard
$text =`pbpaste`;
 
#Convert the text to lower case
$text ="\L$text";
 
#Convert the first character of each word to upper case
$text =~ s/ ((^\w)|(\s\w))/\U$1/xg;
 
#Output the text
print $text;

I might be stuck in the escaping settings as I do not really understand what escaping mean in the context of an Alfred workflow. 

Link to comment

Thanks for your answer.

No, I didn't. 

 

Your workflow let me convert without opening TextExpander, which is very cool. 

 

Here is what I did:

I added a selection in OSX action to make it fill my needs.

 

With your workflow, I need 4 steps to convert a string in an uppercase string. 

1°) selection the content

2°) hit the shortcut I set

3°) select the case I want to convert the case into

4°) paste the upper-cased content

 

I was looking a solution were steps 3 and 4 wouldn't exist. 

 

Just some basic feedback  :)

Link to comment
  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...