用户工具

站点工具


侧边栏

Navigation

hazel

Hazel

简介

可以说是 Mac 平台,最适合普通用户的自动化文件管理 app。

应用实例

结合 automator 将文件导入 DEVONthink pro

DEVONthink pro 提供了很多 automator 的 workflow,可以利用这些 workflow 完成很多操作。

导入文件只要设置以下 automator 的 workflow 即可:

保存该 workflow; 设置 Hazel

这里设置的是导入 Alfred 的 workflow,用 DEVONthink 来管理,其他文件同理。

将 Omnifocus 完成的任务发送至 Day One

原理:监视 Omnifocus 的数据库所在目录,有变化就通过 shell 脚本分析数据结构,符合条件就执行相应的操作。 Hazel 设置如下: 将~/Library/Containers/com.omnigroup.OmniFocus2/Data/Library/Caches/com.omnigroup.OmniFocus2/目录添加到 Hazel 里,Mac App Store 版和官网版的位置不一样,请自行查找。

因为 Omnifocus 的任务完成后会有个同步的操作,所以数据库会被占用,容易导致规则运行失败,故添加了个1分钟后再执行操作的规则,5分钟也行。 脚本: 该脚本需要安装 Day OneCommand Line Interface 命令用法

此脚本原版说明,原版针对的是 Omnifocus 1 ,现改成 Omnifocus 2 能用。

OmniFocusLogDone2DayOne.sh
	#!/bin/sh
	# 
	# Rob Trew www.complexpoint.net
	# https://github.com/RobTrew/tree-tools
	#
	# Ver 0.05
	# Logs today's OmniFocus DONE items in DAYONE, 
	# Avoiding duplication if called several times in one day
	# ( Maintains a text file list of which items have already been logged today )
 
	# Requires installation of the [DayOne Command Line Interface](http://dayoneapp.com/tools/)
	# For more details of the dayone command line tool, try:
	# man -t 'dayone' | pstopdf -i -o ~/Desktop/dayone.pdf
 
	# Can be used with [HAZEL](http://www.noodlesoft.com/hazel.php) rules like:
	## Watch:   ~/Library/Caches/com.omnigroup.OmniFocus
	## or:      ~/Library/Caches/com.omnigroup.OmniFocus.MacAppStore
	##  Date Last Modified is after Date last Matched
	##  <AND> Date last Modified is not in the last 5 mins
 
	# (The delay reduces the number of log events, 
	# allowing time for a small set of actions within one project to be marked as done, 
	# without undue fragmentation into separate DayOne Log events)
 
	# Ver 3 Improves handling of done items from Inbox, 
	# and makes trailling project colon a live link back to the project in the OmniFocus database
	# Ver 4 facilitates choice between plain and bold Project title lines ($PROJECT_PREFIX below)
 
	PROJECT_PREFIX="## " # Edit this to an empty string (see next line) for unbolded Day-One project lines.
	#PROJECT_PREFIX=""
 
	DONE_LOG_FOLDER="$HOME"
	DONE_TODAY_FILE="$DONE_LOG_FOLDER/DoneToday.txt"
	LOGGED_TODAY_FILE="$DONE_LOG_FOLDER/LoggedToday.txt"
	LOG_NOW_FILE="$DONE_LOG_FOLDER/JustDone.txt"
 
	OFOC="com.omnigroup.OmniFocus2"
	if [ ! -d "$HOME/Library/Containers/com.omnigroup.OmniFocus2/Data/Library/Caches/$OFOC" ]; then OFOC=$OFOC.MacAppStore; fi
	OFQUERY="sqlite3 $HOME/Library/Containers/com.omnigroup.OmniFocus2/Data/Library/Caches/$OFOC/OmniFocusDatabase2"
	START_OF_DAY=$(date -v0H -v0M -v0S +%s) #Midnight at the start of today: set the time component to 00:00
	TODAY=$(date "+%Y-%m-%d")
 
	# Suggestions welcome here - not sure this simple arithmetic works for New Zealand's DST +1300 UTC
	ZONERESET=$(date +%z | awk '
	{if (substr($1,1,1)!="+") {printf "+"} else {printf "-"} print substr($1,2,4)}') 
	YEARZERO=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "2001-01-01 0:0:0 $ZONERESET" "+%s")
	DONE="($YEARZERO + t.dateCompleted)";
 
	# This join includes context & folder, to allow for broader queries
	JOIN="(((task tt left join projectinfo pi on tt.containingprojectinfo=pi.pk) t
	left join task p on t.task=p.persistentIdentifier)
	left join context c on t.context = c.persistentIdentifier)
	left join folder f on t.folder=f.persistentIdentifier"
 
	MATCHES="$DONE > $START_OF_DAY"
	# doneTOTAL=$($OFQUERY "SELECT count(*) FROM $JOIN WHERE $MATCHES;")
	# printf "DONE TODAY (%s)\n\n" "$doneTOTAL"
 
	$OFQUERY "
	SELECT c.persistentIdentifier, p.persistentIdentifier, strftime('%Y-%m-%d|%H:%M',$DONE, 'unixepoch'), p.name, c.name
	FROM $JOIN WHERE $MATCHES ORDER BY t.datecompleted 
	" > $DONE_TODAY_FILE
	# Determine what, if anything needs to be logged
	if [ -f $LOGGED_TODAY_FILE ]; then
	    if grep -q $TODAY $LOGGED_TODAY_FILE; then # Find items in the full DONE list which have NOT yet been logged
	       awk 'FNR==NR{old[$0];next};!($0 in old)' $LOGGED_TODAY_FILE $DONE_TODAY_FILE > $LOG_NOW_FILE
	    else # nothing yet logged from today
	        cp -f $DONE_TODAY_FILE $LOG_NOW_FILE
	        rm $LOGGED_TODAY_FILE  # start a fresh 'LoggedToday.txt'
	    fi
	else # Log the whole file, then copy done file to logged file
	   cp -f $DONE_TODAY_FILE $LOG_NOW_FILE
	fi
	# then if the log_now file contains entries, log them, and append the newly logged list to the existing logged list
	if [ -s $LOG_NOW_FILE ] ; then
	echo "" > "tmp_pretty.txt"
	cat $LOG_NOW_FILE | awk -v prj_prfx="$PROJECT_PREFIX" '
	BEGIN {FS="\|"; prj=0; str=""}
	{
	    if (prj!=$5) {prj=$5;
	        if (prj!="") {print ("\n" prj_prfx prj "[:](omnifocus:///task/" $2 ")") >> "tmp_pretty.txt" }
	        else {print ("\nInbox[:](omnifocus:///task/" $1 ")") >> "tmp_pretty.txt"} 
	  }
	  if ($6!=prj) {print ("- " $6 " @done(" $4 ")") >> "tmp_pretty.txt"  }
	  else {{print "- *Project completed* @done(" $4 ")"  >> "tmp_pretty.txt" }}
	}'
	# cat tmp_pretty.txt
	cat tmp_pretty.txt | /usr/local/bin/dayone new
	rm tmp_pretty.txt
	cat $LOG_NOW_FILE >> $LOGGED_TODAY_FILE  # Append the list of logged tasks to avoid duplication
 
	# Optional acoustic feedback on completion... Comment the next line out if it's distracting
	afplay /System/Library/Sounds/Pop.aiff
	fi

脚本运行成功后会播放声音提示。

hazel.txt · 最后更改: 2017/01/19 17:47 由 dr.j

Bitnami