Which clipboard Autokey stores the data with "clipboard.get_selection()" - autokey

Autokey function, text = clipboard.get_selection(), which clipboard is the selected data is stored?
I am using Linux Mint 19.1 Cinnamon with Python 3.6. I am searching for the clipboard storage of Autokey's (Python 3) function, text = clipboard.get_selection().
I assume that it is stored in one of the X clipboard's three clipboards, but none of the Gnome compatible clipboard viewers display it.
I need to know how to refer to the particular clipboard in an Autokey, (or Python), script, to view the data before and after it is being altered by a script.
Paste this code in an Autokey3 keyboard macro. (script) and use any key definition to activate it.
In Linux (or any X11 app), the clipboard owner process must be running to # be able to paste the clipboard contents?
Select any text.
import time
import subprocess
import sys
t_xt = ""
keyboard.send_keys("<ctrl>+a") # select all
time.sleep(.3) # delay of .3 of a second
t_xt = clipboard.get_selection # place selection in clipboard
time.sleep(.3)
keyboard.send_keys(t_xt) # retrieves the t_xt I want to know where this is stored and how I can refer it in an Autokey script?
keyboard.send_keys("<ctrl>+a") # This pastes the contents of a different clipboard.
sys.exit()

According to this documentation, it uses the X mouse selection clipboard.

Related

Programatically change font size in a linux terminal using python

In Ubuntu gnome-terminal it can be done by doing Ctrl + or Ctrl -
Is there a way to write a python script that when executed would resize the font size of the terminal it is executed from?
I need this in order to display images in terminal with high resolution using timg.
Checking the source (vte and gnome-terminal), looks like there's no way to do this. Other terminals (e.g., xterm) can do this using escape sequences. See XTerm Control Sequences:
OSC Ps ; Pt ST
Set Text Parameters. For colors and font, if Pt is a "?", the
control sequence elicits a response which consists of the con-
trol sequence which would set the corresponding value. The
dtterm control sequences allow you to determine the icon name
and window title.
...
Ps = 5 0 -> Set Font to Pt. These controls may be disabled
using the allowFontOps resource. If Pt begins with a "#",
index in the font menu, relative (if the next character is a
plus or minus sign) or absolute. A number is expected but not
required after the sign (the default is the current entry for
relative, zero for absolute indexing).
vte recognizes the 50, but that (like a lot of other xterm features) is just a stub that doesn't do anything. The xterm sources include a 20-year old script which demonstrates the feature (see fonts.sh).
Rather than using an escape sequence, you might be able to use the wmctrl tool (which could ask the window manager to negotiate with the terminal). Some have done that with other terminals, e.g, terminology (but ultimately using an escape sequence).
vte does have some code which might be accessible from a python script, using g_signal_connect to associate decrease-font-size and increase-font-size signal (see source code). The signal code is what you're using with the keyboard. But how you might determine the object pointer from a script starting outside the terminal emulator isn't clear.
There is no easy way to do this across terminals. Terminals support so called control sequences, which can set a bunch of options, like text color and others, but there is no control sequence for setting the font size. See for example https://en.wikipedia.org/wiki/ANSI_escape_code and https://invisible-island.net/xterm/ctlseqs/ctlseqs.html for what kind of actions are supported.

Xcode AppleScript : change label which content of variable

Here is my script :
property MyLabel : missing value
on buttonClicked_(sender)
set the plistfile_path to "~/Desktop/MY_DATA.plist"
tell application "System Events"
set p_list to property list file (plistfile_path)
-- read the plist data
set theMyDataFromPlist to value of property list item "DATA1" of p_list
end tell
end buttonClicked_
This gonna take the data I want from a plist and set in a variable (theMyDataFromPlist).
How can I print this variable on the label "MyLabel" and make the script auto refresh when the data change ?
also, when I click on the text (or another button), can I copy the value to the clipboard. (would set the clipboard to theMyDataFromPlist work?)
I also wonder is that possible to do the same with Swift?
How can I print this variable on the label "MyLabel"
Where would you like to print the variable? You can make AppleScript display a dialog:
set variable to 42
display dialog "The value of variable is " & variable
AppleScript is not designed as a terminal language, it is for UI scripting, so it's not like most scripting languages that just offer a print as where would the user see the printed value.
and make the script auto refresh when the data change ?
Not quite sure what you expect here. That your system magically runs your script whenever the content of a file changes? That's not going to happen. You can create a launchd job and have launchd monitor that file and then execute your script when the file changes; this is described here:
https://discussions.apple.com/message/13182902#13182902
But some process will have to monitor the file and if your script should do so, it has to be running all the time, non-stop. Then you could make some code run once every X seconds, checking the file last modification date and whenever that changes, re-read the plist. This polling is super ugly but the best thing that AS can do out of the box.
BTW where is the rest? You say
also, when I click on the text (or another button),
can I copy the value to the clipboard.
Which text? Which button? Sound like you have a whole application there but all you showed us are 11 lines script code. You didn't even mention that you have a whole application with a UI. Your question starts with "Here is my script", so you make it sound like this 11 lines is all that you have.
(would set the clipboard to theMyDataFromPlist work?)
Why don't you simply try it out? Pasting that line into ScriptEditor would have taken equally long than asking this question. I just tried it and it turns out that you can only set strings.
This code won't work:
-- bad code
set variable to 42
set the clipboard to variable
But this code does work:
-- good code
set variable to 42
set the clipboard to "" & variable
I also wonder is that possible to do the same with Swift?
Personally I would not even consider writing an application in AppleScript; I'd rather stop writing code before I do that. Of course this can be done in Swift or in Obj-C. Everything you can do in AS can be done in these other two languages and no, the opposite doesn't hold true.
Using Obj-C or Swift, you can also use GCD and with GCD monitoring a file for changes is easy. Just see
https://stackoverflow.com/a/11447826/15809

Type a pre defined text when a shortcut key is pressed in Windows 7

I work on mainframes and don't have much knowledge about windows other than playing warcraft :-) hence pardon me if I ask something nooby/silly.
I have a requirement to enter a particular long-text in the current position of a cursor whenever a shortcut key is pressed.
I am thinking of creating a bat file and assigning a windows keyboard shortcut to the bat file and whenever I have requirement to enter the long text, I press the windows shortcut key
and the long text gets typed in the current position of the cursor.
The current position of the cursor can be in any application, like Excel, Word or notepad or Windows dialog prompts.
Could you please let me know if this is possible and point me where I could get some information about this "technique".
Thanks & Regards,
Vasanth.S
To make a single key combo do what you are asking, you may need another program. You can make a link to a batch file, hook up a shortcut and then use the clip command to copy text from a file onto the clipboard. That would require the shortcut and then a Ctrl+V to paste. The batch file would look like this:
clip < c:\SomeDir\sometext.txt
You might like to look at using a clipboard manager - which saves a history of clipboard entries, can search for an entry, and paste it at the cursor.
Ditto and CLCL are both useful and free - which one you use depends on your windows version.
They are hotkey driven for ease of use, but mouse can be used.

Clearing Windows' Clipboard While Using Sikuli Or Jython

I'm trying to clear the Windows' clipboard using Sikuli or Jython.
I'm currently using the clipboard to grab user entered text from a textbox. I use the clipboard to check if the user entered text before clicking a button. I want to check if the textbox was left empty before the button was clicked.
The problem that I am having is that once the clipboard is used, I am unable to clear it. So the value in the clipboard is returned to my script every time the button is clicked.
I need to be able to clear the clipboard after grabbing the user entered text from it, or find a way to read the textbox without using the clipboard.
Help.
Thanks in advance,
Marwan
Using Jython, you can do as follows to set the contents of the clipboard to an empty string, which would be something like clearing it.
from java.awt.datatransfer import StringSelection
from java.awt.datatransfer import Clipboard
from java.awt import Toolkit
toolkit = Toolkit.getDefaultToolkit()
clipboard = toolkit.getSystemClipboard()
clipboard.setContents(StringSelection(""), None)
And as follows to read the contents of the clipboard as a string:
from java.awt.datatransfer import DataFlavor
contents = clipboard.getContents(None)
print contents.getTransferData(DataFlavor.stringFlavor)

How to stop gnuplot window poping-up when using it from command line in windows?

I am using perl to open a pipe to pgnuplot.exe to output plot commands. For example,
open ($PLOT, "|pgnuplot") or die "error: gnuplot not found!";
print $PLOT <<EOPLOT;
set term postscript eps enhanced "Arial" 20
set output "somefile.eps"
## do some plotting here ##
EOPLOT
close $PLOT;
I notice that a window for gnuplot always pops up and grabs the focus of my mouse and keyboard momentarily. This makes it difficult to use the computer while the plot script is running.
Is there any way to stop pgnuplot from opening a window?
Yes, when starting a program in Windows (CreateProcess API) it is possible to request that the main window be hidden or minimized without focus (among other options). But I don't know whether perl provides a easy way to do that.
You might consider using batch operation instead (put your plot commands in a file, then pass the filename to gnuplot).
You can prevent showing child console windows via Win32 module:
use Win32;
Win32::SetChildShowWindow(0);

Resources