Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'An AppleScript to convert the clipboard to plain text' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to convert the clipboard to plain text
Authored by: mistersquid on Sep 06, '07 09:19:25AM

The following AppleScript will transform RTF-formatted contents on the clipboard to plain text and will paste the clipboard into whatever application in which the AppleScript was invoked.

This means that you can use the AppleScript with the launcher/keyboard shortcut utility/accessibility menu of your choice.

Thanks, everyone, for your comments and suggestions.

try
	set the clipboard to Unicode text of (the clipboard as record)
on error errMsg
	display dialog errMsg
end try
tell application "System Events"
	keystroke tab using (command down)
	key code 9 using {command down}
end tell


[ Reply to This | # ]
An AppleScript to convert the clipboard to plain text
Authored by: mistersquid on Sep 06, '07 09:23:21AM

Note: the curly braces and parentheses in the "System Events" code block don't seem to affect the functioning AppleScript. That is, they seem interchangeable.



[ Reply to This | # ]
For the sake of consistency
Authored by: mistersquid on Sep 06, '07 09:49:26AM
try
	set the clipboard to Unicode text of (the clipboard as record)
on error errMsg
	display dialog errMsg
end try
tell application "System Events"
	key code 48 using {command down} --Command-tab
	key code 9 using {command down} --Command-V
end tell


[ Reply to This | # ]
If you want to paste the text into the frontmost application…
Authored by: Stef@nK on Sep 07, '07 07:52:12AM
try this:

try
	set the clipboard to Unicode text of (the clipboard as record)
	tell application "System Events"
		tell process (get 1st process whose frontmost is true)
			keystroke "v" using command down
		end tell
	end tell
on error errMsg
	display dialog errMsg
end try


[ Reply to This | # ]
If you want to paste the text into the frontmost application…
Authored by: mistersquid on Sep 07, '07 10:14:47AM

Did you test the code you proposed?

I've tried my own version of the code you offer as well as your specific code and both do not work.

The failure is due to the fact that the frontmost process ends up being the AppleScript itself! You have to tell System Events to go to the 2nd frontmost process which cannot be done by using "get 2nd process whose frontmost is true".



[ Reply to This | # ]
If you want to paste the text into the frontmost application…
Authored by: Stef@nK on Sep 07, '07 11:28:24AM

Of course I've tested it ;-)
if you start the script from the script menu and not in Script Editor, it should work.



[ Reply to This | # ]