scripts - How can I periodically search ~/Downloads and add new files to Recent? - Ask Ubuntu


i periodically search newly added (created) files inside ~/downloads , add these files list of recent able listed , recognised applications such recent files indicator.

introduction

technically speaking, each gui application chooses register files opens gtk.recentmanager can so, , files appear in application reads recent files, including recent files indicator. however, command line applications don't that. possible , however, track directory , add newly created files recentmanager. script presented below allows doing that.

usage

the usage simple - run script python3 , give list of directories command line arguments. standard rules quoting command-line arguments apply. example:

python3 indexdir.py ~/downloads 

source code:

also available on github:

#!/usr/bin/env python3 # author: serg kolo # date: november 19, 2016 # written for: http://askubuntu.com/q/842038/295286 gi.repository import gtk gi.repository import gio gi.repository import glib import urllib.parse import signal import time import sys import os  class indexer(object):     def __init__(self):         self.callback()      def callback(self,*args):          self.indexdir(sys.argv[1:])          time.sleep(3)          glib.idle_add(gtk.main_quit)      def get_file_uri(self,*args):         file = gio.file.new_for_path(args[-1])         if not file.query_exists(): return none         return file.get_uri()      def indexdir(self,*args):         mgr = gtk.recentmanager().get_default()         recent = [i.get_uri() in mgr.get_items()]         dir in args[-1]:             full_path = os.path.realpath(dir)             file in os.listdir(full_path):                 file_path = os.path.join(full_path,file)                 file_uri = self.get_file_uri(file_path)                 if not file_uri: continue                 if file_uri in recent: continue                 print('>>> adding: ',file_uri)                 mgr.add_item(file_uri)      def run(self,*args):         gtk.main()       def quit(signum,frame):     gtk.main_quit()     sys.exit()  def main():      while true:         signal.signal(signal.sigint,quit)         indexer = indexer()         indexer.run()  if __name__ == '__main__': main() 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User