Activates The Archive and remind for Journaling
#!/bin/bash
# <xbar.title>Journaling with The Archive</xbar.title>
# <xbar.version>v1.0</xbar.version>
# <xbar.author>Bruno Conte</xbar.author>
# <xbar.author.github>brunocbr</xbar.author.github>
# <xbar.desc>Activates The Archive and remind for Journaling</xbar.desc>
# <xbar.image>https://forum.zettelkasten.de/uploads/editor/xm/regzdy1vfk24.gif</xbar.image>
# <xbar.dependencies>bash,applescript,The Archive</xbar.dependencies>
# <xbar.abouturl>https://forum.zettelkasten.de/discussion/1559/better-journaling-with-the-archive-and-bitbar</xbar.abouturl>
SCRIPT_NAME=$(basename "$0")
SCRIPT_DIR=$(dirname "$0")
FLAG_FILE="$TMPDIR/remember-journal.tmp"
MENU_LINE="| bash='${SCRIPT_DIR}/${SCRIPT_NAME}' param1=click terminal=false"
DAY=`date +%Y%m%d`
ALERT_MODE=0
# Bookmark icon by Kiranshastry
# https://pngtree.com/so/bookmark-icon
ICON="iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAlmVYSWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSATEAAgAAABEAAABah2kABAAAAAEAAABsAAAAAAAAAJAAAAABAAAAkAAAAAF3d3cuaW5rc2NhcGUub3JnAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAAQgxyKAAAACXBIWXMAABYlAAAWJQFJUiTwAAACpGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8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HL62N4nTId5vYr9VjHsB6xbZ2cggxajwsgAAAABJRU5ErkJggg=="
INTERFACE_STYLE=$(defaults read -g AppleInterfaceStyle 2>/dev/null)
if [[ "$INTERFACE_STYLE" = "Dark" ]]; then
ICON="iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAlmVYSWZNTQAqAAAACAAFARIAAwAAAAEAAQAAARoABQAAAAEAAABKARsABQAAAAEAAABSATEAAgAAABEAAABah2kABAAAAAEAAABsAAAAAAAAAJAAAAABAAAAkAAAAAF3d3cuaW5rc2NhcGUub3JnAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAAQgxyKAAAACXBIWXMAABYlAAAWJQFJUiTwAAACpGlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS40LjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iCiAgICAgICAgICAgIHhtbG5zOnRpZmY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vdGlmZi8xLjAvIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDx4bXA6Q3JlYXRvclRvb2w+d3d3Lmlua3NjYXBlLm9yZzwveG1wOkNyZWF0b3JUb29sPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICAgICA8ZXhpZjpDb2xvclNwYWNlPjE8L2V4aWY6Q29sb3JTcGFjZT4KICAgICAgICAgPGV4aWY6UGl4ZWxZRGltZW5zaW9uPjUxMjwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj41MTI8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KmmBAAwAAAa5JREFUWAntVztSw0AMtQlQcQFuQcVZkgOk4RThArkAx+AEDHVCQ0cDBTVpCSHmvV29RYmZ+IMpmFnNyE+WpSdF68zIReGkqqoj3gKn0BcoZRuh11W55Joad6jhykYTAccWMHalROBcnU3PMbYaoRZt301FB+QqQrEGlmb/BshBLoq4VWungW2MKc4MR4ZDgLjErVo7DahQ6k6OAbHG7Y9AdYYYu7j2scb9UwP7SX96nxvIE8gTyBPIE8gTyBP49xP4xLJA7S19J8DVagPlrkelXVu34GuUtB43Rn4HcKFkMebemJs7PyfBlavTj+raAItow52VZXmNe37IvAJmtCE+JnraXEESFkbg0j49NoaCtQzghJzAEdXsiXvuY+kW19Jia8spyQ418G7kb8BLIzkhUuALNp9BGUNRDu1ODSyYAVGSiB7hO7eCp6Gyu+BZ8DEGyliKcsW1sPxWE/gAAZVyC9Wo0y939YOJGE2CR8Mciud5ONSACtzHvHSdqxA8jS+tj4E9TyzRuLMG9CKLOr5Q9pDn+AzlWU7NV8Ju/fdiLFTvFD/1V9An6IXxJa4v4JNxsnlzsu0AAAAASUVORK5CYII="
fi
CUR_ICON=${ICON}
if [[ -f "${FLAG_FILE}" ]]; then
CUR_ICON=${ICON_ALERT}
ALERT_MODE=1
fi
function switchTheArchive() {
if [[ "${ALERT_MODE}" = 1 ]] ; then
open "thearchive://match/${DAY}"
else
osascript <<EOF
tell application "System Events"
set activeApp to name of application processes whose frontmost is true
if (activeApp begins with "The Archive") then
set visible of application process "The Archive" to false
else
do shell script "open \"thearchive://match/${DAY}\""
end if
end tell
EOF
fi
}
if [[ "$1" = "click" ]]; then
switchTheArchive
if [ -f "${FLAG_FILE}" ] ; then
rm -f "${FLAG_FILE}"
open 'xbar://refreshPlugin?name=journal.sh'
fi
fi
echo "$MENU_LINE image=${CUR_ICON}"