Skip to content

Commit

Permalink
added logging + fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Jun 3, 2022
1 parent 54d72a1 commit 6cf9f06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3166,13 +3166,13 @@ to set a hotkey for the citaiton picker.</string>
<key>backup_destination</key>
<string>~/Library/Mobile Documents/com~apple~CloudDocs/Dotfolder/Backups/Library Backups/</string>
<key>bibtex_library_path</key>
<string>~/.pandoc/main-bibliography.bib</string>
<string>~/Library/Mobile Documents/com~apple~CloudDocs/File Hub/13-46-10.bib</string>
<key>bibtex_tidy_options</key>
<string>--duplicates=key,doi --numeric --tab --no-align --tidy-comments --strip-enclosing-braces --remove-empty-fields --drop-all-caps --remove-dupe-fields --omit=month,issn,pagetotal --backup --quiet --sort-fields --escape</string>
<key>csl_folder</key>
<string>~/.pandoc/csl</string>
<key>literature_note_folder</key>
<string>~/Library/Mobile Documents/iCloud~md~obsidian/Documents/Main Vault/Literature Notes/</string>
<string></string>
<key>match_authors_in_etal</key>
<string>true</string>
<key>match_only_short_years</key>
Expand Down
15 changes: 11 additions & 4 deletions scripts/buffer_writer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ObjC.import("stdlib");
const app = Application.currentApplication();
app.includeStandardAdditions = true;
const homePath = app.pathTo("home folder");

const urlIcon = "🌐";
const litNoteIcon = "📓";
Expand All @@ -15,17 +16,19 @@ const alfredBarLength = parseInt ($.getenv("alfred_bar_length"));

const matchAuthorsInEtAl = $.getenv("match_authors_in_etal") === "true";
const matchOnlyShortYears = $.getenv("match_only_short_years") === "true";
const libraryPath = $.getenv("bibtex_library_path").replace(/^~/, app.pathTo("home folder"));
const litNoteFolder = $.getenv("literature_note_folder").replace(/^~/, app.pathTo("home folder"));
const pdfFolder = $.getenv("pdf_folder").replace(/^~/, app.pathTo("home folder"));
const libraryPath = $.getenv("bibtex_library_path").replace(/^~/, homePath);
const litNoteFolder = $.getenv("literature_note_folder").replace(/^~/, homePath);
const pdfFolder = $.getenv("pdf_folder").replace(/^~/, homePath);
let litNoteFolderCorrect = false;
if (litNoteFolder) litNoteFolderCorrect = Application("Finder").exists(Path(litNoteFolder));
let pdfFolderCorrect = false;
if (pdfFolder) pdfFolderCorrect = Application("Finder").exists(Path(litNoteFolder));
if (pdfFolder) pdfFolderCorrect = Application("Finder").exists(Path(pdfFolder));

// Import Hack, https://github.com/JXA-Cookbook/JXA-Cookbook/wiki/Importing-Scripts
const toImport = "./scripts/bibtex-parser.js";
console.log ("Starting Buffer Writing");
eval (app.doShellScript(`cat "${toImport}"`));
console.log ("Parser Import successfull.");

// -------------------------------

Expand All @@ -38,6 +41,7 @@ if (litNoteFolderCorrect) {
.split("\r")
.filter(filename => filename.endsWith(".md"))
.map (filename => filename.slice(0, -3)); // remove extension
console.log ("Literature Note Reading successfull.");
}

if (pdfFolderCorrect) {
Expand All @@ -49,12 +53,14 @@ if (pdfFolderCorrect) {
.replace (/.*\/(.*)_.*/, "$1") // only citekey part
.replaceAll ("_", ""); // remove underscores from citekey additional stuff (personal naming convention from older library)
});
console.log ("PDF Folder reading successfull.");
}

// -------------------------------


const rawBibtex = app.doShellScript(`cat "${libraryPath}"`);
console.log ("Bibtex Library Reading successfull.");

const entryArray = bibtexParse(rawBibtex) // eslint-disable-line no-undef
.map(entry => {
Expand Down Expand Up @@ -194,6 +200,7 @@ const entryArray = bibtexParse(rawBibtex) // eslint-disable-line no-undef
});

// -------------------------------
console.log ("Buffer Creation successfull.");

const logEndTime = new Date();
console.log("Buffer Writing Duration: " + (logEndTime - logStartTime).toString() + "ms");
Expand Down
1 change: 0 additions & 1 deletion scripts/open_buffer.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/zsh
# shellcheck disable=SC2154
LIBRARY="${bibtex_library_path/#\~/$HOME}"
BUFFER="$alfred_workflow_data/buffer.json"
LAST_VERSION_FILE="$alfred_workflow_data/last_version.txt"
Expand Down

0 comments on commit 6cf9f06

Please sign in to comment.