Jump to content
politicus

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. 

Share this post


Link to post

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  :)

Share this post


Link to post

I've posted an updated version set up for use with hotkeys - once you set the corresponding keys for your step 3 above, it should provide the automated process you're looking for.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...