How I wrote Ulauncher extension for most used timedate macros

Why?

#!/bin/sh
alias setclip='xclip -selection c'
alias getclip='xclip -selection clipboard -o'
printf $(date +"%Y-%m-%d") | setclip

How?

About my extension

{
"required_api_version": "^2.0.0",
"name": "Timestamp macros",
"description": "Copy to clipboard the most used timedate formats",
"developer_name": "Nurgazy Nazhimidinov",
"icon": "images/icon.png",
"options": {
"query_debounce": 0.05
},
"preferences": [
{
"id": "time_kw",
"type": "keyword",
"name": "Timemacros",
"default_value": "tm"
}
]
}
class DemoExtension(Extension):    def __init__(self):
super(DemoExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener): def on_event(self, event, extension):
items = []
logger.info('preferences %s' % json.dumps(extension.preferences))
logger.info(event.get_keyword()) # gives the keyword 'tm'
items.append(ExtensionResultItem(icon='images/icon.png',
name='YYYY-MM-DD',
description='{0:%Y-%m-%d}'.format(datetime.datetime.now()),
on_enter=CopyToClipboardAction('{0:%Y-%m-%d}'.format(datetime.datetime.now()))))
items.append(ExtensionResultItem(icon='images/icon.png',
name='HH:mm',
description='{0:%H:%M}'.format(datetime.datetime.now()),
on_enter=CopyToClipboardAction(
'{0:%H:%M}'.format(datetime.datetime.now()))))
items.append(ExtensionResultItem(icon='images/icon.png',
name='YYYY-MM-DD HH:mm',
description='{0:%Y-%m-%d %H:%M}'.format(datetime.datetime.now()),
on_enter=CopyToClipboardAction(
'{0:%Y-%m-%d %H:%M}'.format(datetime.datetime.now()))))
return RenderResultListAction(items)
if __name__ == '__main__':
DemoExtension().run()
items.append(ExtensionResultItem(icon='images/icon.png',
name='YYYY-MM-DD',
description='{0:%Y-%m-%d}'.format(datetime.datetime.now()),
on_enter=CopyToClipboardAction('{0:%Y-%m-%d}'.format(datetime.datetime.now()))))

Summary

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store