Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

od with date_format = "yyyy-mm-dd" only includes 1 digit for day #5

Closed
technicalpickles opened this issue Nov 3, 2020 · 3 comments
Closed

Comments

@technicalpickles
Copy link

Here's my osascript:

// step 1: specify daily note date format
// example 1: "yyyy-m-d"  if your date format looks like 1990-3-1
// example 2: "yymmdd"    if your date format looks like 900301
// example 3: "yy-m-dd"   if your date format looks like 90-3-01

// indicate your date format below by replacing "yyyy-mm-dd" with your format
date_format = "yyyy-mm-dd"; 

// step 2: specify vault name
v = "pickled-knowledge";

When I run od, I get:

image

Two other things that might be relevant:

  • my daily notes go into a Daily/ folder
  • I hadn't created a Daily Note yet (it fails with the same error even when it does exist)
@hauselin
Copy link
Owner

hauselin commented Nov 3, 2020

Hi @technicalpickles, thanks for letting me know. I've just fixed it.

Cool vault name, btw! ;)

@hauselin
Copy link
Owner

hauselin commented Nov 3, 2020

Also, if it's easier, in the osascript for today's note, you can simply replace the code after //don't need to edit the lines below with the code below. Other aspects of the workflow haven't changed.

// don't need to edit the lines below
date_format = date_format.toLowerCase();

// determine no. of y, m, d needed
n_y = date_format.split('y').length - 1;
n_m = date_format.split('m').length - 1;
n_d = date_format.split('d').length - 1;
y_char = "y".repeat(n_y);
m_char = "m".repeat(n_m);
d_char = "d".repeat(n_d);

// get today's date
today = new Date();
yyyy = today.getFullYear().toString();
mm = (today.getMonth() + 1).toString();
dd = today.getDate().toString();

// format date according to user specification (e.g., yy, m, d)
yyyy = yyyy.slice(4-n_y, 4);
if (mm.length == 1) {mm = mm.padStart(2, '0').slice(2-n_m, 2)};
if (dd.length == 1) {dd = dd.padStart(2, '0').slice(2-n_d, 2)};

date_format = date_format.replace(y_char, yyyy);
date_format = date_format.replace(m_char, mm);
date_format = date_format.replace(d_char, dd);

p = encodeURIComponent(v) + "&file=" + date_format + ".md";
uri = "obsidian://open?vault=" + p;

// get the current app to access the standard additions
app = Application.currentApplication();
app.includeStandardAdditions = true;

// open file in vault
app.openLocation(uri);
console.log(uri);

@technicalpickles
Copy link
Author

Awesome, thanks! I had worked out a solution at about the same time, but without knowing about padStart 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants