Need script to lowercase text string and replace spaces with hyphens

I am a novice when it comes to AppleScript, so please forgive this really simple question.

I want a script that will do the following:

  1. Grab the current text on the clipboard.
  2. Lowercase the text.
  3. Replace spaces in the text with hyphens.
  4. Insert the new text at the current cursor location.

So, for example, if I had the following on the clipboard:

The script would change it to this:

Can someone please share a simple script to do this?

Thanks.

Model: MacBook Pro
AppleScript: 2.0.1
Browser: Firefox 3.0.4 GTB5
Operating System: Mac OS X (10.5)

Hi,

try this


set the clipboard to (do shell script "echo " & quoted form of (get the clipboard) & " | tr A-Z' ' a-z-")
tell application "System Events"
	set currentApplication to name of 1st process whose frontmost is true
	tell process currentApplication to keystroke "v" using command down
end tell

the script must be run from the script menu. It won’t work when you run it in Script Editor

Hi StephanK

It seems that you you know the use of the terminal.

How may we get a more serious UPPER to lower converter.

You response treats only 26 characters but they are more numerous.

Think to the good old ÉÈÀÒÙÌÂÊÎÔÄËÏÖÜÆŒÃÕÁĂȦÉÍĨ

If I rember well it would require Perl or Python but I don’t know how to use them.

Yvan KOENIG (from FRANCE vendredi 27 février 2009 16:04:48)

The easiest way is to install SatImage OSAX


set s to "ÉÈÀÒÙÌÂÊÎÔÄËÏÖÜÆŒÃÕÁĂȦÉÍĨ"
set s to lowercase s
--> "éèà òùìâêîôäëïöüæœãõáăȧéíĩ"

I would suggest using either TextCommands (you can find it on www.osaxen.com) or Satimage.osax (go to www.satimage-software.com for the latest version).

I don’t like to use third party products when I write scripts for users asking in forums.
Most of the time they don’t know what they are.

With a bit of luck, I remembered an old script which I posted at the end of 2008 on an other forum.

--[SCRIPT]
set leNom to my convert("THIS IS AN UPPERCASE FILE NAME_ÉÈÀÒÙÌÂÊÎÔÄËÏÖÜÆŒÃÕÁAÉÍI˜.png", "lower")
on convert(n, choix)
	--choix = "lower"
	--set choix = "upper"
	--set choix = "title"
	return (do shell script "/usr/bin/python -c \"import sys; print unicode(sys.argv[1], 'utf8')." & choix & "().encode('utf8')\" " & quoted form of n)
end convert
--[/SCRIPT]

Yvan KOENIG (from FRANCE vendredi 27 février 2009 17:45:27)

Thanks so much. It works perfectly for my needs.

Model: MacBook Pro
AppleScript: 2.0.1
Browser: Firefox 3.0.4 GTB5
Operating System: Mac OS X (10.5)