Sublime Forum

Copy text from the Status Bar?

#1

Is there a setting, a builtin key binding, or package available that would let me copy text from the Status Bar to the pasteboard? Could you point me in the right direction?

1 Like

#2

What text are you trying to get?

The only available method of getting status bar text is view.get_status( key ), but it requires that you know the key of the particular text you want to extract.

IMO there should be something like view.get_all_statuses(), which would return an array of tuples containing [ ( key_1, value_1 ), ... ]
 


 
A workaround would be to search the plugin you want to extract text from for set_status & use the string value of their key with the get_status command.

There’s also a status_message command that developers can use to post messages, but I don’t believe there is an associated key; so you might not be able to extract the text in that case.

1 Like

#3

I already looked at the particular plugin that has the message I want, in this case Rubocop, and it uses the key rubocop when posting status bar messages, so I can just assign a hotkey to view.get_status( 'rubocop' ) to get the message? I’ll try that.
I like your suggestion, I could even live with view.get_status_keys(), but I prefer yours.

0 Likes

#4

I can create a hotkey that issues the command, but How do I get the text to the pasteboard?

0 Likes

#5

Save This @:

/Packages/CopyRubocopStatus/CopyRubocopStatus.py

 

import sublime, sublime_plugin

class copy_rubocop_status( sublime_plugin.TextCommand ):
	def run( self, edit ):

		status = self.view.get_status( "rubocop" )
		sublime.set_clipboard( status )

 



Add This @:

Preferences > Key Bindings - User

 

{
	"keys": [ "ctrl+shift+alt+c" ],
	"command": "copy_rubocop_status",
},
1 Like

#6

Thanks for your help. I followed your directions, when I hit the hotkey combo I get a new clipboard entry with “No prinatable characters” I have to move on now, I will fool around with this later.

0 Likes

#7

a little more investigating, if I set status to a literal string, that string is copied to pasteboard. So the problem is that status is not being populated properly. Rubocop sets the status at line 143 of rubocop_listener.py My best guess is that it’s a scoping problem, or possibly some weird issue with the Rubocop status message structure

0 Likes

#8

What happens if you create an override of rubocop_listener.py & change line 143 to:

view.set_status('rubocop', str('RuboCop: {0}'.format(view_dict[row])))
0 Likes

#9

@fico Thanks for all the help. I made the change you suggested and get the same result.

0 Likes

#10

I got it working here. Change this line:

status = self.view.get_status( "rubocop" )

To:

status = sublime.active_window().active_view().get_status( "rubocop" )

They should not be the same thing?
Why they are getting different results?
Someone know? Is this a bug within Sublime Text?

Here I when I do:

class GetScopeAlwaysTextCommand( sublime_plugin.TextCommand ):

	def run( self, edit ):

		// status = self.view.get_status( "scope_always" )
		status = sublime.active_window().active_view().get_status( "scope_always" )
		print( status )

The first one (commented) get text.plain which is wrong.
But the second one get the correct result source.octave source.matlab punctuation.definition.brackets.begin.matlab

0 Likes