In this post:
- Introduction
QuickPhrase_Time.py
script
xclip
shortcut
1.Introduction
The plugin to which OP refers to, is QuickPhrase and can be installed via sudo apt-get install fcitx-modules fcitx-module-quickphrase-editor
. It uses ~/.config/fcitx/data/QuickPhrase.mb
to store phrases.
The main objective here is to have easy way of inserting a string which contains current time into text filed that user is currently editing. Below there are two solutions.
2. QuickPhrase_Time.py script
This script continuously edits the line in config file which has time_now
phrase , and appends current time to the line. This script is meant to be launched automatically on login to GUI.
Usage is simple:
python /path/to/QuickPhrase_Timer.py
Script source
Also available as Github Gist , updated versions likely will go there.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import subprocess
import time
import os
def run_cmd(cmdlist):
""" Reusable function for running external commands """
new_env = dict( os.environ )
new_env['LC_ALL'] = 'C'
try:
stdout = subprocess.check_output(cmdlist,env=new_env)
except subprocess.CalledProcessError:
pass
else:
if stdout:
return stdout
if __name__ == '__main__':
user_home = os.path.expanduser('~')
config_file = '.config/fcitx/data/QuickPhrase.mb'
config_full_path = os.path.join(user_home,config_file)
found = None
while True:
lines = []
time.sleep(1)
with open(config_full_path) as f:
for line in f:
lines.append(line.strip())
if line.startswith('time_now'):
found = True
# print(lines)
if found:
with open(config_full_path,'w') as f:
for line in lines:
if line.startswith('time_now'):
time_now = run_cmd(['date',
'+%Y-%m-%d %I:%M'
]).decode().strip()
line = 'time_now ' + time_now + '\n'
else:
line = line + '\n'
f.write(line)
3. xclip shortcut
In case the above python script won't work for you, here's a workaround: bind the command below to a keyboard shortcut
xclip -sel clip <<< $( date +%Y-%m-%d\ %I:%M )
Essentially, what this does is copies output of date
to your clipboard, which you can then release via Ctrl+V shortcut ( which is common for most applications as paste shortcut).
This approach doesn't rely on fctix
or any other input method, hence is more flexible and reliable.
Note that xclip
is not installed by default. Obtain it via sudo apt-get install xclip
fcitx
orxim
or any other - doesn't matter. It still going to work, because it uses clipboard – Sergiy Kolodyazhnyy Aug 23 '16 at 05:27quickphrase
plugin. It will be quite easy, I think. Just a question. How do I trigger the keyword ? likesmile
? – Sergiy Kolodyazhnyy Aug 23 '16 at 05:54