AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 19250
Accepted
Peter.O
Peter.O
Asked: 2010-12-30 07:44:40 +0800 CST2010-12-30 07:44:40 +0800 CST 2010-12-30 07:44:40 +0800 CST

是否有一个应用程序可以根据窗口的标题将备忘录链接到窗口?

  • 772

鹦鹉螺有它的notes-for-files
假小子有它的笔记linking-ideas
屏幕本身有它的sticky notes

是否有用于记下特定窗口的笔记的应用程序?
...可能基于窗口的标题,并通过快捷键显示..

software-recommendation notes
  • 2 2 个回答
  • 232 Views

2 个回答

  • Voted
  1. Best Answer
    Peter.O
    2011-01-01T04:17:24+08:002011-01-01T04:17:24+08:00

    好吧,我又一次进入了学习曲线……(深夜和大量咖啡)。

    最终结果是一个适度可用的 bash 脚本(使用 sqlite db/table),它完成了我所追求的...
    ...即。根据窗口标题创建一组注释...

    它有效..但它绝对是“阿尔法”..

    所以,我有我自己开发的应用程序!...我在这里为任何对“看看”感兴趣的人发布...

    这里是:


    #!/bin/bash
    
    clearAllDataAndStartAgain="false"
    
    # Name: tinotes (Title Notes)
    # 
    # What does it do? ... Aside from giving me a great opportunity to learn
    #      more about bash (and sqlite, which I had previously barely touched).. not much ;)
    #      Actually, it allows you to keep notes, grouped by window title.
    #      The notes are kept in an sqlite database. 
    #      Each timestamped note-"event" is stored in a row of the main (only) table.
    #      You can consolidate notes in a semi ad-hoc manner... 
    #      Notes are presented to you in a single editable text file (in Leafpad).  
    #      You must keep at least one "tinotes" timestamp-line at the top of the text...
    #      All lines above this topmost timestamp-line are ignored,
    #      including the "title", which is presented upon each viewing.
    #      If you remove any/all other "timestamp line(s)", those particular rows are 
    #      deleted from the sqlite table, and the text which remains is associated with
    #      the immediately preceding timestamp-line (and updated as such in the sqlite table)
    #         
    # How do you drive it? .. Just associate `tinotes.sh` with a shortcut-key.. That's' it!
    #      Just press the shortcut-key and you will be presented with Leafpad displaying 
    #      a  "title line" at the very top, and on line 2, is a "tinotes timestamp" line.  
    #      Type your note below the  timestamp-line, then Save and Exit Leafpad,..
    #      NB.. You MUST fully EXIT Leafpad.. the script cannot proceed until you EXIT Leafpad..
    #      Leafpad is effectively being used as a Dialog-box with "normal" editing capability.
    #      A warning Dialog appears if another instance of this script is currently running.. 
    #      (actually, if another ***tinotes** leafpad window is running).
    #             
    # Caveat: This version is very much "demo-only"... 
    #         It works, but has typical "alpha" bugs... 
    #         I've presented it here, for anyone who is interested in the general idea.
    #             
    # dependencies
    # ============
    #      sqlite3 ,, the notes are stored in a sqlite db.
    #      leafpad .. to edit/view the notes (no need to re-invent the wheel)
    #       wmctrl .. to detect if a ***tinotes*** leafpad window is currently open.
    #      xdotool .. to get the active window's' ID
    #     xwininfo .. to get a window's title via it's ID.
    #       md5sum .. to check for mods to the presented/added notes data 
    #       zenity .. for warning dialog(s)
    #          sed .. versatile!
    #           wc .. word count? .. line count (here)
    
    ############################################################################
    
    function FinalizeNote {
      title="$1"; note="$2"; timeline="$3"; preList="$4"
    
      # Remove trailing whitespace
      note="${note%"${note##*[![:space:]]}"}"
      # Does this timestamp exist in the  PRE-LIST
      timestamp=${timeline:0:19}
      preCt=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList" |wc -l)
      if [ "$preCt" -eq "0" ] ; then
          sqlite3 "$appdb" "INSERT INTO Tmain (time,title,note) VALUES('$timestamp','$title','$note');"
      elif [ "$preCt" -gt "1" ] ; then
          excod=3
          zenity --error --text "$preCt duplicate timestamps found. \
          \nThis is an 'alpha' problem! \
          \n\n    Exiting with code $excod"
          exit $excod
      else
          # TODO: At it currently stands, it is only known that "something" has changed, 
          #       but not which rows have been effected. (Just update them all, for now.)
          id=$(sed -n "s/^$timestamp.\(.*\)/\1/p" "$preList")
          sqlite3 "$appdb" "UPDATE Tmain SET note='$note' WHERE id='$id';"
          # Remove line from PRE-LIST
          sed -i -e "/^$timestamp.*$/d" "$preList"
      fi
    }
    
    ############################################################################
    
      sep="∘" # Field seperator 
      sepmulti="∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘∘"
      sepfirst="∘∘(write∘new∘notes∘below∘this∘line)∘∘"
      appnam="tinotes"
      appdir="$HOME/.$appnam"
      appdb="$appdir/$appnam.db"
      appsql="$appdir/$appnam.sql"
      apptxt="$appdir/$sep$sep$sep$appnam$sep$sep$sep"
      preList="$appdir/$appnam.pre"; echo -n>"$preList"
    
      tiwid=0 # Check for a currently running Instance of the "Leafpad"  window...   
      tiwid=$(wmctrl -l |sed -n "s/\([^ ]\+\) \+[^ ]\+ \+[^ ]\+ \*\?$(basename $apptxt)$/\1/p")
      if [ "${tiwid:0:2}" == "0x" ] ; then
          # Warn of the need to finalize an already-running instance of this script
          zenity --warning  --text "You must first finalize a previously opened \n\t 'tinotes' window.\
          \n\n  To activate the window, select 'OK'"
          # 'wmctrl' can only activate via a title
          #   ..and it is case-insensitive and wildcarded!! 
          # so use 'xdotool'
          xdotool windowactivate --sync $(($tiwid))
          exit
      fi
    
      #################################################################################################################################################
      [ "$clearAllDataAndStartAgain" = "true" ] && [ -d "$appdir" ] && rm -rf  "$appdir" # Typically for TESTING ONLY; Remove all data,and start afresh!  
      #################################################################################################################################################
    
      # First-time create app's main directory
      [ ! -d "$appdir" ] && mkdir   "$appdir"
      # First-time Create the Tmain table
      [ ! -f "$appdb" ] && sqlite3 "$appdb" "create table Tmain (id INTEGER PRIMARY KEY,time DATE,title TEXT,note TEXT);"
    
    # Get the active-window's title
    # =============================
      activeT=$(xwininfo -id "$(xdotool getactivewindow)" |sed -n \
      "2s/^xwininfo: Window id: \(0x[[:xdigit:]]\+\) \x22\(.*\)\x22$/\2/p")
    
    # Does a previous row of the same title already exist?
    # ====================================================
      # First, prepare a new/"empty" note entry
        echo "$activeT" >"$apptxt"
        echo -e $(date '+%Y-%m-%d %H:%M:%S' |tr -d '\n')" $sep$appnam$sepfirst\n\n\n">>"$apptxt"
    
      # Count existing rows for this title
      if [ $(sqlite3 "$appdb" "SELECT COUNT(title) FROM Tmain WHERE title = '$activeT';") -gt 0 ] ; then
          # Previous notes FOUND for this window title
          # Make a list of timestamps to match-off against any user mods 
          sqlite3 "$appdb" "SELECT time,id FROM Tmain WHERE title='$activeT';" >"$preList"
    
          # Build and Run the query to construct the "timeline"
          echo -e ".separator "$sep"\n\
          SELECT time||' $sep$appnam$sepmulti','\n\n'||note||'\n' FROM Tmain WHERE title='$activeT' order by time desc;">"$appsql"
          sqlite3 "$appdb" <"$appsql">>"$apptxt"
      fi
      # Present the notes to the user (get the  "before" md5sum, to compare with user's access/mods)  
      md5bef=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
      leafpad "$apptxt" # The script waits for the user to close "leafpad"
      md5aft=$(md5sum "$apptxt" |sed "s/\([[:xdigit:]]\+\).*/\1/")
      # Check for any modifications to the notes
      if [ "$md5bef" == "$md5aft" ] ; then
          # No changes have been made.
          exit 0
      fi
      # The notes have been modified. Commit the changes!
      # It's time to analyze the changes, and tidy up.
      #   Remove leading and trailing blank lines (per timestamp).
      #   Delete rows for which the timestamp has been removed.
      #   Update the table for all the remaining rows.
      note=""
      lnCt=0
      while read line ; do
          lnCt=$((lnCt+1))
          [ "$lnCt" -eq "1" ] && continue  # The first line is a throw-away copy of the "title"
          # Find timeline. Any leading data is lost. (It shouldn't be there... common-sense!)
          if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\ ∘.*∘$ ]] ; then
              # FOUND timeline
              if [ "$note" != "" ] ; then
                  FinalizeNote "$activeT" "$note" "$timeline" "$preList"
              fi
              note=""
              timeline=$line
          elif [ "$line" = "" ] ; then
              if [ "$note" != "" ] ; then
                  note="$note$line"$'\n' # append this blank line
              fi
          else
              note="$note$line"$'\n' # append this non-blank line
          fi 
      done <"$apptxt"
      #
      if [ "$note" != "" ] ; then
          FinalizeNote "$activeT" "$note" "$timeline" "$preList"
      fi
      # Delete rows for timestamps still in the PRE-LIST
      while read line ; do
          eval $(echo "$line" |sed -n "s/.*|\([0-9]\+\)$/id=\1/p")
          sqlite3 "$appdb" "DELETE FROM Tmain WHERE id='$id';"
      done <"$preList"
    
    exit 
    
    ############################################################################
    
    • 1
  2. MarkovCh1
    2010-12-30T09:17:51+08:002010-12-30T09:17:51+08:00

    嗯,我能想到的最好的方法就是ccsm按名称选择窗口(我将从“窗口规则”插件开始)。有一种方法可以按名称移动或粘贴窗口,所以如果你给你的窗口命名,并且你很聪明,也许这可以工作......

    • 0

相关问题

  • 有哪些科学绘图软件可用?

  • 最好的思维导图软件是什么?

  • 服务器的最佳rootkit删除工具?

  • 从 Ubuntu 连接到 Windows 的最佳远程桌面工具是什么?[关闭]

  • 是否有 Paint.NET 替代方案?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何安装 .run 文件?

    • 7 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    如何获得 CPU 温度?

    • 21 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Marko Smith

    你如何重新启动Apache?

    • 13 个回答
  • Marko Smith

    如何卸载软件?

    • 11 个回答
  • Marko Smith

    如何删除 PPA?

    • 26 个回答
  • Martin Hope
    NES 如何启用或禁用服务? 2010-12-30 13:03:32 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    Olivier Lalonde 如何在结束 ssh 会话后保持进程运行? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B 如何使用命令行将用户添加为新的 sudoer? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans 如何删除旧内核版本以清理启动菜单? 2010-08-21 19:37:01 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve