You can also watch this video at YouTube (but with ads).
A Shortcut To Enclose Text In Quotes Using Automator
Comments: 18 Responses to “A Shortcut To Enclose Text In Quotes Using Automator”
Comments Closed.
You can also watch this video at YouTube (but with ads).
For MacMost episodes like this, would it be possible for you to either (a) provide a downloadable ZIP file or (b) provide a text file of the text that you entered into Automator? Thank you for considering this.
.
Douglas: I usually do (include the code). But since this is just one line, I didn't do it this time. The line is just:
Be careful when copying and pasting as the outer quotes need to be straight quotes, and the characters in the middle need to be the curly ones.
Thanks very much for the video - educational, elegant and informative. I particularly enjoy your Automator tutorials.
I created this script and would like to revise it. How do I find it? I thought it would be in the Automator library. Also, will this work in Word or Mail? I've tried with no success. So far, I can only get it to work in Pages. Thanks always for your great tips!
Jim: Launch Automator. File, Open Recent. Then, while you have it open, Command+click the filename in the title bar to see the path for next time.
Was a wonderful taste of what can be accomplished with Automator.
Here is a future challenge: capture text that has a date and time and convert it to a Calendar Event.
Thanks again for these stellar videos.
Tim: That would be tricky since there are so many ways one can format a date. But you can often already do this with Data Detectors. I should be a new video on those soon.
Thanks for the useful tip.
I understand a Javascript function key=key.replace(/ /g,"_"); searches for spaces in a selection and will replace them with underscores.
But I don't know Javascript. How do you implement this in your Automator example?
Don: Pretty much just as you put it. The variable is input, not key, so just change that.
input = input.replace(/ /g,"_");
(make sure you use straight quotes, not curly ones).
Thanks - I've adapted this trick to help create local file links.
Step1: Service receives FILES OR FOLDERS in FINDER.APP.
Step2: Gary's Run JavaScript but with "input = "file://" + input;". Now I can select a file/folder, run the Service, which creates text of the form like "file:///Users/WXYZ/Documents/chart.pdf" which can be used as clickable link to the file. You can embed them in Note/Evernote etc to help organise project that have files/folders in different places.
Wen I use ⌘' in Pages, TextEdit and Notes apps it works fine. When I try it in Mail in either a new message or a reply message it changes the text color to blue but doesn't add any quote marks.
Bob: That keyboard shortcut is already in use in Mail, so pick another one. I was just using it as an example in the tutorial.
Doesn't seem to matter. I disabled all shortcuts except for that one and I also changed the shortcut for Enclose in Quotes to multiple different key combinations not already used and none of them work when pressing the set keyboard combination. But, any key combination I set for Enclose in Quotes works when I click on Mail, Services, Enclose in Quotes.
Bob: I tried Shift+Command+' (quote) and it worked in Mail for me. Of course, I have to be composing a message for it to work, as you can't add text to a message you are reading, as opposed to composing.
Gary: Thanks again for the help, but another dummie question after trying your suggestion...
function run(input, parameters) {
input = input.replace(/ /g,"_");
return input;
}
This returned a “Error on line 3: TypeError: input.replace is not a function. (In 'input.replace(/ /g,"_")', 'input.replace' is undefined)”.
What's needed?
Maybe JavaScript isn't happy that the input variable may or may not be a string. Try this to force it to be a string:
function run(input, parameters) {
str = ""+input;
str = str.replace(/ /g,"_");
return str;
}
Gary: Outstanding tip! Works like a charm.
I now have a useful group of Services to manipulate filenames by simply substituting one line in your suggested script.
Replace Spaces with Hyphens: str = str.replace(/ /g,"-");
Replace Spaces with Underscores: str = str.replace(/ /g,"_");
Replace Hyphens with Spaces: str = str.replace(/-/g," ");
Replace Underscores with Spaces: str = str.replace(/_/g," ");
Plus this global search and replace technique could be expanded for other applications.
Don - " Services to manipulate filenames..." I find this only seems to work on text, say within in TextEdit but not on Finder names. Am I missing something?? Changing filenames is exactly what I would like to be able to do.