I have an Applescript which - simplified - looks like this:

display dialog "foo" default answer ""

One of the users of this script runs Lion. Whenever he tries to copy/paste a string to the input dialog, that won't work if the origin of the copy has got some formatting (e.g. the string is copied from a web page). Everything works fine under Snow Leopard.

Any hint on why this happens?

  • 3
    This appears to be a new bug in Lion. It seems the problem is specifically with copying text that is any color other than pure white or pure black. – joelseph Sep 7 '11 at 5:20
  • Are you able to select the txt and drag it to the AppleScript dialog box? I have seen this work properly a time or two, where Copy/Paste failed... But I don't know that it will work with AppleScript. – TheWellington Sep 14 '11 at 22:37

I've found the same thing -- if I copy/paste from TextEdit in Rich Text mode, I cannot paste into the input field. If I change the mode to plain text, it works fine.

Here's an Applescript I found that worked for me. It works by converting the clipboard to plain text:

  set the clipboard to string of (the clipboard as record)
on error errMsg
  display dialog errMsg
end try

You need to make it an executable script and then bind it to a keyboard shortcut. After that, whenever you copy some formatted text, execute the keyboard shortcut and you can then paste the text without problems.

| improve this answer | |
  • 1
    Because links to external sites often break, it is helpful to summarize the content of the linked site and not just post a link. – Daniel Jan 31 '12 at 20:52
set variable_name to (the clipboard as text)
| improve this answer | |

I tried to reproduce the problem with

on run
    set dialogResult to display dialog "foo" default answer ""
    set newText to text returned of dialogResult
    display dialog "Text entered: " & newText
end run

but at least at first sight it appears to be working ok. Which specific issue did you run into ("won't work" is a bit broad)?


The problem has been fixed in OS X 10.8, just got a mail from devbugs@apple.com:

14-Sep-2012 07:40 PM Apple Developer Bug Reporting Team :

We believe this issue has been addressed in OS X 10.8 (Mountain Lion) GM Seed (Build 12A269). This pre-release version is available now on the Mac App Store to Mac Developer Program eligible members.  Please verify with this release and update your bug report with the results.

| improve this answer | |
  • 1
    Try copying and pasting gray text (or any color other than pure white or black). In this case "won't work" means the text can't be pasted into the AppleScript dialog. – joelseph Sep 23 '11 at 1:41
  • I've tried it with formatted text from the AppleScript editor, from TextEdit and from several web sites and didn't run into any problems. Are we talking about a specific site here? – nohillside Sep 23 '11 at 6:48
  • 1
    Interesting. It looks like certain other colors do work, like AppleScript's blue color for commands, but not for its green color for variables, or the shades of gray on this page's answers (15% white) and comments (20%), or the word "set" or the word "foo" in your script. If you could try those, too, maybe we can see if it's an actual bug or we just have something wonky going on in our systems. I have now found a handful of other colors that work, but randomly setting colors in TextEdit almost always results in pasting not working. – joelseph Sep 23 '11 at 15:35
  • Indeed. Selecting just a green variable name from AppleScript Editor doesn't work, selecting the whole line does. I've raised Bug ID# 10175210 at bugreport.apple.com. – nohillside Sep 23 '11 at 16:04
  • 1
    Not fixed with 10.7.2 :-( – nohillside Oct 23 '11 at 9:42

This is a bit of a kludge, but I would imagine it works: Copy the text and paste it into something such as Notational Velocity, BBEdit, TextEdit or some other text processor that supports text without formatting. If you have NV set to plain text, simply re-copy it and you're set. In BBEdit and TextEdit there are commands to remove formatting.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .