Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Paste as Plain Text" Action #230

Closed
kerim opened this issue Apr 21, 2011 · 29 comments
Closed

"Paste as Plain Text" Action #230

kerim opened this issue Apr 21, 2011 · 29 comments
Assignees

Comments

@kerim
Copy link

kerim commented Apr 21, 2011

I would like to have the default action for text be "Paste as Plain Text" but currently there is no such action. THere is a "Paste with clipboard" action, but that pastes as styled text, not plain text.

@skurfer
Copy link
Member

skurfer commented Apr 21, 2011

You can enter pbpaste then use the “Run Command in Shell” to sort of strip the formatting. (The result will come back to Quicksilver at which point you can paste it.)

The fact that I know that should tell you that other people have a need for something like this. There should be an easier way.

@ghost ghost assigned skurfer Apr 21, 2011
@skurfer
Copy link
Member

skurfer commented Apr 25, 2011

So I’m thinking there are two scenarios we care about here:

  1. Pasting something that’s in Quicksilver’s first pane (from clipboard history or some other source)
  2. Pasting the contents of the clipboard as plain-text (if possible)

For the first scenario, to literally paste something as plain text, we’d have to put it in the clipboard as the most recent item which would replace whatever was there. I’m hesitant to do that (but then again the current Paste action does this). It would be nice to paste the plain text version of something without creating a new entry in the clipboard. I don’t know if that could be done, but there is something very similar: the Type Text action. However, that only works well for small amounts of text. Is it worth it to modify the clipboard to pull this off?

The second scenario is another animal, but one I’m sure we would like to see. This would have to be provided by something in the first pane. A proxy object representing the plain text version of the current item maybe? And I have to wonder if there’s already a way to do this.

@kerim
Copy link
Author

kerim commented Apr 27, 2011

Here's how it works for me in Launch bar, which I'm very happy with:

  1. I copy something.
  2. I hit a command-key sequence to open up my clipboard history.
  3. To input the current clipboard item as plain text I simply hit return, for an older item I scroll and hit return.

That's it. I almost never, ever, want to paste as styled text. Ever since OS X came out this has driven me crazy, because I almost always want to match the existing style, not preserve the old style. However, if I do want to paste styled text I can hold the control key when I hit return. (The default settings can be flipped in the preferences.)

@skurfer
Copy link
Member

skurfer commented Apr 27, 2011

The clipboard history operates outside the normal interface, so that would have to be a preference item or something.

Although it is possible to access the items within Quicksilver using Show Contents or Search Contents, at which point you could run other actions on them.

@machad
Copy link

machad commented Apr 28, 2011

@lovequicksilver pointed me here. I actually created an action for this last night using AppleScript and posted the solution here:

http://www.webrealm.org/2011/04/paste-unformatted-text-with-quicksilver.html

It's no substitute for the real solution Skurfer is working on, but it's something to tide us over!

@skurfer
Copy link
Member

skurfer commented Apr 28, 2011

I was thinking a solution for the second scenario could be an addition to the Extra Scripts plug-in. AppleScript isn’t my thing. Would you know how to take “the thing currently in the clipboard” and paste it as text (instead of the thing from Quicksilver’s first pane)? If so, could we use this in the plug-in? (If you’re really ambitious, you could fork the Plugins repository and submit a pull request, but that’s a lot to wrap your head around if you’re not familiar.)

@machad
Copy link

machad commented Apr 28, 2011

I'm not that great an AppleScript coder myself, but I got this code to work. Maybe later tonight, I can try to figure out how to get this into the repository; I've never actually used Git but one has to learn some time!

tell application "Finder" to set frontApp to (name of 1st process whose frontmost = true)
set oldClipboard to (the clipboard as record)
do shell script "pbpaste |pbcopy"
tell application frontApp
activate
tell application "System Events" to keystroke "v" using command down
end tell

delay 1
set the clipboard to oldClipboard

@machad
Copy link

machad commented Apr 28, 2011

Thinking about it, there is a downside to both of these AppleScripts: they add to the clipboard history - twice. The action replaces the current clipboard with the contents of the clipboard history, then again with the plain-text version. The script above replaces the contents of the clipboard with the plain-text version, then again with the original version when it's finished pasting.

That seems like a nuisance bug, but a nuisance none the less. I don't really know how to get around that.

@skurfer
Copy link
Member

skurfer commented Apr 28, 2011

Things already show up there over and over. I was going to suggest a list of modifications for the clipboard stuff and this is one of them: see if something matches what’s already there before adding it again. Also, if it came from QS’s own history, delete it from the old position and move it to the top.

For pasting as plain text, adding something new is probably unavoidable, but since it’s technically a different thing, I don’t mind it as much. (Although it would be nice, if the text was already plain, not to replace the original.)

@machad
Copy link

machad commented Apr 28, 2011

I like the idea of not replacing text if it's already plain, but it doesn't seem doable using the conversion method above. I tried some string comparison to see if copied plain text is the same as the result of a pbpaste. Even copying Terminal, which we know is plain text, appears to be different based on my tests. I suspect this is because copying in OS X probably always contains some style data, even if that data is "no style." That's distinctly different from pbcopy and pbpaste, which appear to have no style data at all. Even using pbpaste -Prefer rtf yields no positive result in the string comparison.

I'm using the pbpaste |pbcopy because it's my understanding that the other method I know - set the clipboard to «class ktxt» of ((the clipboard as text) as record) - has a limit to how many characters it can handle. I'm not sure what that limit is or how likely it is a user will ever hit that limit, but I do know that pbcopy and pbpaste interact directly with the clipboard. That's why I ultimately went with that method where I had previously tried the other.

@slambert
Copy link

You can do this with the existing code by using "Type Text" instead of pasting.

@pjrobertson
Copy link
Member

@skurfer are you doing anything with this?
I'd completely forgotten about the 'type text' action. Does this work for all cases?

I'd got this far until I realised you were assigned to the issue (editing QSActionProvider_EmbeddedProvider.m)

    -(QSObject *)pasteObject:(QSObject *)dObject {
[self pasteObject:dObject asPlainText:NO];
return nil;
    }

    - (QSObject *)pasteObject:(QSObject *)dObject asPlainText:(BOOL)plainText{
if(!dObject) {
    return nil;
}
if (plainText) {
}
if ([dObject putOnPasteboard:[NSPasteboard generalPasteboard]]) {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"WindowsShouldHide" object:self];
    [[NSApp keyWindow] orderOut:self];
    QSForcePaste();
} else NSBeep();
return nil;
    }

@skurfer
Copy link
Member

skurfer commented May 15, 2011

The type text action works well for a few words or a line, but it’s inadequate for general use. It’s too slow and if you “type” into an application that does auto-indenting, all kinds of weird stuff can happen.

I’ve got a branch for it, but not much has been done. I guess I’d like to fix the issue with duplicates in the history before copying/extending the behavior of the existing paste action.

Do you think this needs to be done for ß60? It was originally under that milestone but I took it out a while back when I realized it was more complicated than I first thought.

@pjrobertson
Copy link
Member

Paste with plain text should be a pretty simple fix no?

I just need to expand on the code written above: make a new text object from
the object, or grab the text and format to plain text, then do the usual
paste.

The business with adding duplicate items to the pasteboard - I should be
able to fix that once I take a look at the method I mentioned in the other
thread - once an object's been copied and pastes to the pasteboard, the
Clipboard plugin is clearly not seeing it as the same object.

P.S.
I want to merge the shelf and clipboard plugin into one: any objections?

On 15 May 2011 19:06, skurfer <
reply@reply.github.com>wrote:

The type text action works well for a few words or a line, but its
inadequate for general use. Its too slow and if you type into an
application that does auto-indenting, all kinds of weird stuff can happen.

Ive got a branch for it, but not much has been done. I guess Id like to
fix the issue with duplicates in the history before copying/extending the
behavior of the existing paste action.

Do you think this needs to be done for 60? It was originally under that
milestone but I took it out a while back when I realized it was more
complicated than I first thought.

Reply to this email directly or view it on GitHub:
#230 (comment)

@machad
Copy link

machad commented May 15, 2011

That reminds me, I was going to figure out how to check that in. I'll do that now!

@pjrobertson
Copy link
Member

That reminds me, I was going to figure out how to check that in. I'll do
that now!

What was that?

P.S. that reminds me of another paste bug: I'll put it here as it's late and
I'm off shortly.
Perhaps someone could verify (@skurfer ?) and post a new issue?

If you try and paste a URL (I'm assuming any HTML data) into a textarea (?)
it doesn't work.

Steps to reproduce:

  1. Compose a new email in Gmail
  2. In QS, type 'http://qsapp.com' in the 1st pane.
  3. Tab and select 'paste with clipboard'
  4. Doesn't work.If you do it e.g. in the location bar or To: field in Gmail
    it works.

Strange

On 15 May 2011 23:53, machad <
reply@reply.github.com>wrote:

That reminds me, I was going to figure out how to check that in. I'll do
that now!

Reply to this email directly or view it on GitHub:
#230 (comment)

@machad
Copy link

machad commented May 15, 2011

Good news / less good news; I sorted out how to fork the Plugins repository, but I don't actually see the Extra Scripts plugin to add the script to. Has that been changed?

@machad
Copy link

machad commented May 15, 2011

@pjrobertson: Skurfer suggested I learn git (which I really ought to do anyway) and check the AppleScript I'd mentioned above into the Extra Scripts plugin, then submit a pull request.

@pjrobertson
Copy link
Member

We don't have the source for the extra scripts plugin (yet).

I'll be adding it to the repo very shortly. :)
Is it a script for a 'paste as plain text' action? Mind putting up a link
here? If it's decent enough there may be no need to write a cocoa method,
although it'd probably be quicker.

On 16 May 2011 00:16, machad <
reply@reply.github.com>wrote:

@pjrobertson: Skurfer suggested I learn git (which I really ought to do
anyway) and check the AppleScript I'd mentioned above into the Extra Scripts
plugin, then submit a pull request.

Reply to this email directly or view it on GitHub:
#230 (comment)

@machad
Copy link

machad commented May 15, 2011

Here's the source:

using terms from application "Quicksilver"
    on process text _text
        try
            set the clipboard to «class ktxt» of ((_text as text) as record)
        on error errMsg
            display dialog errMsg
        end try

        try
            tell application "System Events"
                keystroke "v" using command down
            end tell
        end try
    end process text
end using terms from

@skurfer
Copy link
Member

skurfer commented May 15, 2011

I just need to expand on the code written above: make a new text object from the object, or grab the text and format to plain text, then do the usual paste.

I think a plain-text representation already exists for all copied text. There’s stuff in NSPasteBoard like dataForPasteboardType:, so I imagine we could pull the plain-text type for the current contents and then add it to the pasteboard …unless it’s already there! ;) I think the type we want is “public.utf8-plain-text”, but I haven’t tested that.

If you try and paste a URL (I'm assuming any HTML data) into a textarea (?) it doesn't work.

I can’t reproduce this. Pasting a hand-typed URL works and so does pasting formatted HTML from a web page. (I tested here on GitHub. Maybe it’s something with Gmail?)

I want to merge the shelf and clipboard plugin into one: any objections?

None, but this could be confusing for users and/or cause them problems. Which of the two would the new combined version update? Or would it be a third plug-in? And either way, how would we warn every single person to remove the obsolete versions manually before using this one?

@pjrobertson
Copy link
Member

Quick reply:

I think the type we want is public.utf8-plain-text, but I havent tested
that.

Close. I think the name's changed in Snow Leopard (the whole pasteboard
stuff changed)
You're probably right - that's the best way to do it.

Pasting a hand-typed URL works and so does pasting formatted HTML from a
web page

Pretty sure it's just GMail text areas (probably somewhere else as well),
but it's annoying.

And either way, how would we warn every single person to remove
the obsolete versions manually before using this one?

Using our code that we've yet to write to check for 'known bad plugins' on
launch, and them to deleting them ;)

On 16 May 2011 05:10, skurfer <
reply@reply.github.com>wrote:

I just need to expand on the code written above: make a new text object
from the object, or grab the text and format to plain text, then do the
usual paste.

I think a plain-text representation already exists for all copied text.
Theres stuff in NSPasteBoard like dataForPasteboardType:, so I imagine we
could pull the plain-text type for the current contents and then add it to
the pasteboard unless its already there! ;) I think the type we want is
public.utf8-plain-text, but I havent tested that.

If you try and paste a URL (I'm assuming any HTML data) into a textarea
(?) it doesn't work.

I cant reproduce this. Pasting a hand-typed URL works and so does pasting
formatted HTML from a web page. (I tested here on GitHub. Maybe its
something with Gmail?)

I want to merge the shelf and clipboard plugin into one: any objections?

None, but this could be confusing for users and/or cause them problems.
Which of the two would the new combined version update? Or would it be a
third plug-in? And either way, how would we warn every single person to
remove the obsolete versions manually before using this one?

Reply to this email directly or view it on GitHub:
#230 (comment)

@skurfer
Copy link
Member

skurfer commented May 16, 2011

I think the name's changed in Snow Leopard (the whole pasteboard stuff changed)

I got that name by running pasteboardTypes on the current pasteboard. See, I did work on this a little. :)

Using our code that we've yet to write to check for 'known bad plugins’ on launch, and them to deleting them ;)

Good call. Yet another reason to create such a thing.

@skurfer
Copy link
Member

skurfer commented May 26, 2011

We don't have the source for the extra scripts plugin (yet).

Just FYI, I’ve found this plug-in in the repo. It’s in the Codeless folder.

@pjrobertson
Copy link
Member

The pasteboard plugin?

I've already altered the code quite a bit and fixed quite a few things -
didn't realise it was difficult to find (I just use spotlight on the
QSPlugins folder to find stuff)

On 27 May 2011 02:51, skurfer <
reply@reply.github.com>wrote:

We don't have the source for the extra scripts plugin (yet).

Just FYI, Ive found this plug-in in the repo. Its in the Codeless
folder.

Reply to this email directly or view it on GitHub:
#230 (comment)

@skurfer
Copy link
Member

skurfer commented May 27, 2011

The pasteboard plugin?

No, Extra Scripts.

@pjrobertson
Copy link
Member

Just a few things on this:

  1. Sorry @skurfer if you've also done it, but in the middle of fixing the other bug I've opened on pasting URLs into things like Google, I also wrote a pasteeAsPlainText action
  2. The reason you get duplicate items on the clipboard shelf is because they're not actually the same object. They're the same text, but with different 'types' defined (e.g. some will have NSURLPboardType, while others just NSStringPboardType)

@skurfer
Copy link
Member

skurfer commented May 28, 2011

That’s fine with me. I unassigned myself from it a while ago when it seemed like you were looking at it. :)

@ghost ghost assigned pjrobertson Jul 25, 2011
@skurfer
Copy link
Member

skurfer commented Jul 25, 2011

Implemented in #439. There’s a “Paste as Plain Text” action. You can use it directly, or as an alternate to the regular “Paste” action by holding ⌘. This doesn’t affect what happens using the clipboard window, but that might come later.

@skurfer skurfer closed this as completed Jul 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants