date2name/README.org
2018-02-03 17:16:50 +01:00

193 lines
8.4 KiB
Org Mode

* Handling time-stamps and date-stamps in file names
[[file:screencast.gif]]
Per default, date2name gets the modification time of matching files
and directories and adds a datestamp in standard ISO 8601+ format
YYYY-MM-DD (http://datestamps.org/index.shtml) at the beginning of
the file- or directoryname.
If an existing timestamp is found, its style will be converted to the
selected ISO datestamp format but the numbers stays the same.
Executed with an examplefilename "file" this results e.g. in
"2008-12-31_file".
Note: Other that defined in ISO 8601+ the delimiter between hours,
minutes, and seconds is not a colon but a dot. Colons are causing
several problems on different file systems and are there fore replaced
with the (older) DIN 5008 version with dots.
: Usage:
: date2name [options] file ...
Run "date2name --help" for usage hints
: Options:
: -h, --help show this help message and exit
: -d, --directories modify only directory names
: -f, --files modify only file names
: -C, --compact use compact datestamp (YYYYMMDD)
: -M, --month use datestamp with year and month (YYYY-MM)
: -w, --withtime use datestamp including seconds (YYYY-MM-DDThh.mm.ss)
: -m, --mtime take modification time for datestamp [default]
: -c, --ctime take creation time for datestamp
: -q, --quiet do not output anything but just errors on console
: -v, --verbose enable verbose mode
: --nocorrections do not convert existing datestamps to new format
: -s, --dryrun enable dryrun mode: just simulate what would happen, do
: not modify files or directories
: --version display version and exit
* Installation
Get it from [[https://github.com/novoid/date2name][GitHub]] or install it via «pip install date2name».
* Integration Into Common Tools
** Integration into Thunar
[[https://en.wikipedia.org/wiki/Thunar][Thunar]] is a popular GNU/Linux file browser for the xfce environment.
Unfortunately, it is rather complicated to add custom commands to
Thunar. I found [[https://askubuntu.com/questions/403922/keyboard-shortcut-for-thunar-custom-actions][a good description]] which you might want to follow.
To my disappoinment, even this manual confguration is not stable
somehow. From time to time, the IDs of ~$HOME/.config/Thunar/uca.xml~
and ~$HOME/.config/Thunar/accels.scm~ differ.
For people using Org-mode, I automated the updating process (not the
initial adding process) to match IDs again:
Script for checking "tag": do it ~tag-ID~ and path in ~accels.scm~ match?
: #+BEGIN_SRC sh :var myname="tag"
: ID=`egrep -A 2 "<name>$myname" $HOME/.config/Thunar/uca.xml | grep unique-id | sed 's#.*<unique-id>##' | sed 's#<.*$##'`
: echo "$myname-ID of uca.xml: $ID"
: echo "In accels.scm: "`grep -i "$ID" $HOME/.config/Thunar/accels.scm`
: #+END_SRC
If they don't match, following script re-writes ~accels.scm~ with the current ID:
: #+BEGIN_SRC sh :var myname="tag" :var myshortcut="<Alt>t"
: ID=`egrep -A 2 "<name>$myname" $HOME/.config/Thunar/uca.xml | grep unique-id | sed 's#.*<unique-id>##' | sed 's#<.*$##'`
: echo "appending $myname-ID of uca.xml to accels.scm: $ID"
: mv $HOME/.config/Thunar/accels.scm $HOME/.config/Thunar/accels.scm.OLD
: grep -v "\"$myshortcut\"" $HOME/.config/Thunar/accels.scm.OLD > $HOME/.config/Thunar/accels.scm
: rm $HOME/.config/Thunar/accels.scm.OLD
: echo "(gtk_accel_path \"<Actions>/ThunarActions/uca-action-$ID\" \"$myshortcut\")" >> $HOME/.config/Thunar/accels.scm
: #+END_SRC
** Integration into Windows Explorer for single files
Create a registry file =add_date2name_to_context_menu.reg= and edit it
to meet the following template. Please make sure to replace the paths
(python, =USERNAME= and =date2name.py=) accordingly:
#+BEGIN_EXAMPLE
Windows Registry Editor Version 5.00
;; for files:
[HKEY_CLASSES_ROOT\*\shell\date2name]
@="date2name (single file)"
[HKEY_CLASSES_ROOT\*\shell\date2name\command]
@="C:\\Python36\\python.exe C:\\Users\\USERNAME\\src\\date2name\\date2name.py -i \"%1\""
#+END_EXAMPLE
Execute the reg-file, confirm the warnings (you are modifying your
Windows registry after all) and cheer up when you notice "date2name
(single file)" in the context menu of your Windows Explorer.
As the heading and the link name suggests: [[https://stackoverflow.com/questions/6440715/how-to-pass-multiple-filenames-to-a-context-menu-shell-command][this method works on single
files]]. So if you select three files and invoke this context menu item,
you will get three different filetag-windows to tag one file each.
** Integration into Windows Explorer for single and multiple selected files
Create a batch file in your home directory. Adapt the paths to meet
your setup. The content looks like:
: C:\Python36\python.exe C:\Users\USERNAME\src\date2name\date2name.py -i %*
If you want to confirm the process (and see error messages and so
forth), you might want to append as well following line:
: set /p DUMMY=Hit ENTER to continue ...
My batch file is located in =C:\Users\USERNAME\bin\date2name.bat=. Now
create a lnk file for it (e.g., via Ctrl-Shift-drag), rename the lnk
file to =date2name.lnk= and move the lnk file to
=~/AppData/Roaming/Microsoft/Windows/SendTo/=.
This way, you get a nice entry in your context menu sub-menu "Send to"
which is also correctly tagging selection of files as if you put the
list of selected items to a single call of date2name.
** Integration into FreeCommander
[[http://freecommander.com/en/summary/][FreeCommander]] is a [[https://en.wikipedia.org/wiki/File_manager#Orthodox_file_managers][orthodox file manager]] for Windows. You can add
filetags as an favorite command:
- Tools → Favorite tools → Favorite tools edit... (S-C-y)
- Create new toolbar (if none is present)
- Icon for "Add new item"
- Name: date2name
- Program or folder: <Path to date2name.bar>
- =date2name.bat= looks like: (please do modify the paths to meet your requirement)
: C:\Python36\python.exe C:\Users\YOURUSERNAME\src\date2name\date2name %*
: REM optionally: set /p DUMMY=Hit ENTER to continue...
- Start folder: =%ActivDir%=
- Parameter: =%ActivSel%=
- [X] Enclose each selected item with ="=
- Hotkey: select next available one such as =Ctrl-1= (it gets overwritten below)
- remember its name such as "Favorite tool 01"
- OK
So far, we've got =date2name= added as a favorite command which can be
accessed via menu or icon toolbar and the selected keyboard shortcut.
If you want to assign a different keyboard shortcut than =Ctrl-1= like
=Alt-d= you might as well follow following procedure:
- Tools → Define keyboard shortcuts...
- Scroll down to the last section "Favorite tools"
- locate the name such as "Favorite tool 01"
- Define your shortcut of choice like =Alt-d= in the right hand side of the window
- If your shortcut is taken, you'll get a notification. Don't
overwrite essential shortcuts you're using.
- OK
* Related tools and workflows
This tool is part of a tool-set which I use to manage my digital files
such as photographs. My work-flows are described in [[http://karl-voit.at/managing-digital-photographs/][this blog posting]]
you might like to read.
In short:
For *tagging*, please refer to [[https://github.com/novoid/filetag][filetag]] and its documentation.
See [[https://github.com/novoid/date2name][date2name]] for easily adding ISO *time-stamps or date-stamps* to
files.
For *easily naming and tagging* files within file browsers that allow
integration of external tools, see [[https://github.com/novoid/appendfilename][appendfilename]] (once more) and
[[https://github.com/novoid/filetag][filetag]].
Moving to the archive folders is done using [[https://github.com/novoid/move2archive][move2archive]].
Having tagged photographs gives you many advantages. For example, I
automatically [[https://github.com/novoid/set_desktop_background_according_to_season][choose my *desktop background image* according to the
current season]].
Files containing an ISO time/date-stamp gets indexed by the
filename-module of [[https://github.com/novoid/Memacs][Memacs]].
* How to Thank Me
I'm glad you like my tools. If you want to support me:
- Send old-fashioned *postcard* per snailmail - I love personal feedback!
- see [[http://tinyurl.com/j6w8hyo][my address]]
- Send feature wishes or improvements as an issue on GitHub
- Create issues on GitHub for bugs
- Contribute merge requests for bug fixes
- Check out my other cool [[https://github.com/novoid][projects on GitHub]]