Go to Home and Go to Journals point to the same all-journals view. Shouldn’t Go To Home actually zoom in onto the today’s Journal? Logseq would feel much speedier if, instead of loading duuno how many journals it would just go straight to today’s journal for Go To Home (if the user didn’t define another home, of course).
Or, is it possible to configure, in config.edn, the home dynamically? So that it always points out to today’s journal (zoomed-in on it)?
Ok, being currently on Windows (but on Linux/MacOS I assume it would work the same), I tried created a Page with the date format I have inside Logseq settings (for me it’s EEEE, dd.MM.yyyy), for today being Friday, 01.09.2023 and, although the actual journals page is named yyyy_mm_dd.md, Logseq complains that I have two pages with the same name. I wanted to have EEEE, dd.MM.yyyy.md as HomePage Name so I can have full consistency with how the Page and the Journals will present the Journal day Title in the app.
As a workaround I created a “symlink” (technically it’s a hardlink) to today’s journal as Friday, 01.09.2023 (today) and it works as expected. G H takes me to the Page, wich is actually a “symlink” to today’s journal page. I also have to put the name of the page into the :default-home {:page "Friday, 01.09.2023 (today)", :sidebar ["Contents"]} declaration in config.edn.
Now, letting aside that I would have to create a powershell script to have this done for each new day while also deleting the symlink in /pages for the day before, I wanted to check with you if you know of any way to trigger this script execution relying solely on Logsec executables (something like runs from time to time and on which I can piggy-back somehow the execution of this script -it doesn’t matter if it’s executed every 5 minutes). If that is not an option, then I would have to create a scheduled task in windows to be run say every minute until it detects that the journal page has been created and execute the “symlink” creation command. This is because the actual file doesn’t get created on disk until I write something into it, even if it’s set to use a Daily Template.
So my question is: is it possible to trigger a powershell script execution without relying on the OS? Maybe a java-script that does the same?
I have asked similar questions to no response. How to set "default-home" to TODAY, not journals for example.
What is mind boggling is that the shortcut of “g t” is “go to tomorrow” but there’s nothing for “go to today”.
I thought I had raised a feature request but cannot find it now from this phone.
Would love to hear if you ever have any success with what should be an obvious improvement.
I have re-mapped those shortcuts to G N ( go Next ) and G B ( go Back ) because of that, hoping that I can manage to hack a G T someday.
I have thought about it quite a lot some time ago but G H actually expects a page (as in /pages folder) to be the destination of the shortcut. It can’t be the journal page ( as in /journals folder). So my approach, for which I started to work out some powershell script code, was to create the journal file for tomorrow (so I make sure it exists) and then to create a sort of symbolic link from the /pages folder, with a slightly different name (Logseq doesn’t like to have two files with the same name even if they are in different folders -which surprised me). I ended up with adding “(today)” to the Journal Page Name (the date). The script would also update the config.edn in the ":default-home {:page … " section so it removes yesterday’s page and replaces it with today’s.
The one thing that I haven’t managed to get right is how to hook this script to the executable of Logseq so it execute every time Logseq is started but that should be easy in Windows by creating a batch file that runs the script and also starts Logseq and I would use that file to open Logseq.
Sounds overkill and maybe it is, that’s why I haven’t developed it fully, but it is something that stays on my mind and I will do it eventually.
PS: I don’t know if this can be done from the custom.js file that can be created and that is ran every time Logseq starts… I am sure that a js dev can easily do that.
I am not knowledgeable enough with js to do anything with it …
I have a go-to-home.ps1 file in the same folder as custom.js which does what I need and, instead of tying it to a batch file that is executed alongside logseq.exe, I would like to run the file from custom.js.
Is that possible with a simple call from custom.js?
I have a solution that works. It involves two files in the same location. I am using the logseq folder -where the custom.edn file is in::
a powershell script file containing the code to:
delete previous hardlinks, if they exist;;
create both journal page in /journals and the hardlink to it under /pages if they don’t exist;
add the name of the hardlink to the ‘:default-home’ section of config.edn;
a Windows Shortcut file with the following characteristics:
Name: Logseq.exe ← you can pick whatever name here;
Target: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noProfile -WindowStyle Hidden -Command "& '.\go-to-home.ps1'; Start-Process -FilePath 'C:\\Logseq\Logseq.exe'"
, where C:\\Logseq\Logseq.exe is the Path to your Logseq install;
Start in: D:\MyGraph\logseq ← this is the folder where config.edn is located in;
Run: Minimized ← this way you won’t see the powershell CLI blink on screen before it’s closed;
In actuality, the go-to-home.ps1 looks like:
# function that creates in /pages a hardlink to the Today's journal file and adds it to config.edn ":default-home" section
function go-to-home {
param (
$numDays = 0
)
# checking if there are any lingering links from past days;
$hardlinksToDelete = Get-ChildItem -Path "..\pages" | Where-Object {
$_.Name -match '\w,\s{1}\d{2}\.\d{2}\.\d{4}\s+\(today\)\.md' -and $_.CreationTime.Day -lt (Get-Date).Day}
# if there are, delete them (will not delete their target, the journal file);
foreach ($link in $hardlinksToDelete) {
Remove-Item $link.FullName
}
# check for journal and test for link; if not there, create it;
for ($i = $numDays; $i -ge 0; $i--) {
# get today's Journal Page;
$journal = "..\journals\$($(Get-Date).AddDays($i).ToString('yyyy_MM_dd')).md"
# create a name for the hardlink (adds a "(toda)" to the internal name of the Journals)
# the internal name is based on the Preferred date format in Logseq Settings
# mine is "EEEEE, dd.MM.yyyy"
$pageHardlink = "$($(Get-Date).AddDays($i).ToString('dddd, dd.MM.yyyy')) (today)"
# if the journal page isn't yet created, create it
if (! (Test-Path $journal)) {
New-Item -ItemType File -Path $journal; echo '';
}
#if the hardlink page is not there, create it as well
if (!(Test-Path "..\pages\$pageHardlink.md")) {
New-Item -ItemType HardLink -Path "..\pages\$pageHardlink.md" -Target $journal; echo ''
}
}
# here we replace/insert in the ':default-home' section in config.edn the name of the hardlink
$config = Get-Content "../logseq/config.edn"
# if there is content inside config.edn and the hardlink is not already there
if ($config -and ($config -notmatch ":default-home {:page `"$PageHardlink`"")) {
# replace whatever is there as the Home-Page with the created hardlink
$config -replace `
'(^\s*):default-home {:page ".*?"', `
"`t:default-home {:page `"$PageHardlink`"" `
| Set-Content "../logseq/config.edn"
}
}
# end function
# call the function
go-to-home
Hi, I was looking for the go-to-today keymaps and found the article.
It seems like your solution is windows-based. Do you have any idea how macOS would use your solution by any means?
I don’t have any experience on macOS and even if you can install -i guess- powershell on macOS I would do this with native scripts. If macOS is anything like Linux then some sort of shell is available, zsh if I’m not mistaken. But I wouldn’t know how to do what I did for Windows with Powershell and Windows Shortcut.
Regarding a solution I would suggest writing a simple script which creates both the /journals/*md file for the next day and a symlink to it from /pages and deletes previous day’s symlink in /pages and schedule this script with launchd (i see there are quite a few tutorials online about how to do that).
PS: creating the *md file in /journals must follow the rule in your current file naming (mine is YYYY_mm_dd.md). For the symlink in /pages I would use a similar name to what you see in your Logseq’s Journal Titles, which is based on your Settings > Editor > Preferred date format but not identical.
Maybe someone with access to a Linux/mac environment can assist with that.
Update : after overcomplicating things with symlinks/hardlinks from page in /pages to current journal file and getting doubled results for some querries -as Logseq was seeing both the linked file and the actual file separately, I somehow moved the linked file away from logseq folder while the current day’s name remained in the :default-home section of config.edn and it seems that is all that is necessary for G H to link to the actual journal page and not to the journals stream.
So, bottom line:
To have G H functionality in Logseq one has to add to the config.edn file, in section :default-home, the name of the current journal page, in the format that is configured in Logseq > Settings > Editor > Prefered date format (the way one sees it as the title of the journal page in Logseq)
It can be done several ways. In Windows, create a shortcut file and call this script before calling logseq.exe as I demonstrated above. Other way is to create a Scheduled Task that runs this powershell script at 00:00 but is also triggered at computer boot-up as well as at computer wake-up (from sleep) -this is how I have itatm.
The easiest would be for someone to write a javascript code that would do this. I don’t know how to do this with javascript but that would be able to use logseq-only tools to achieve the same.
At this point, the go-to-home.ps1 looks like this:
# function that writes the current day's journal name (as seen in Logseq UI) to the config.edn ":default-home" section;
function go-to-home {
# here I get the journal files's name in my Logseq Date format:
$journal_name = "$($(Get-Date).ToString('dddd, dd.MM.yyyy'))"
# here I get the path to config.edn;
$config_edn_path = Get-ChildItem -Path (Get-Location).Drive.Root -Filter config.edn -Recurse -ErrorAction SilentlyContinue |? { $_.DirectoryName -notlike '*Backup*' }|Select -ExpandProperty FullName -First 1
# here I replace/insert in the ':default-home' section in config.edn the name of the journal as seen inside Logseq UI;
$config = Get-Content $config_edn_path
# if there is content inside config.edn and the journal name is not already there
if ($config -and ($config -notmatch ":default-home {:page `"$journal_name`"")) {
# replace whatever is there as the Home-Page with the created hardlink
$config -replace `
'(^\s*):default-home {:page ".*?"', `
"`t:default-home {:page `"$journal_name`"" `
| Set-Content "$config_edn_path"
}
}
# end function
# call the function
go-to-home
I was redirected here because the title of your feature request sounds exactly like what I want, but the rest of your comments seem, well, I can’t follow what you’re trying to do.
I have voted for this request, but I think the execution of this could be much simpler.
As mentioned here, I think we should be able to implement something like this:
:default-home {:page "today"}
where “today” is just today’s journal page, and not the “journals” page.
This should be internal to the logic of LogSeq and should not require coding on the user side.
As I noted with barely contained frustration, I also don’t know why ‘yesterday’ and ‘tomorrow’ have shortcuts, but there is nothing for ‘today’.
Why not “g t” for ‘today’ and "g T’ for tomorrow? Wouldn’t this be a more intuitive solution?
Or, if folks don’t agree, let us use “g h” for “go home to today” and keep “g j” for "go to journals (plural) page.
(At least for now, I can use “g t g p” for going to tomorrow, then the previous entry, but it’s mind-blowing that TODAY, of all days, is not a default option.)
I gave up using Powershell script to edit config.edn and replace the date in :default-home { with current date formatted according to my Date Preferences in Logseq and instead wrote a javascript function jut to get rid of as many externalities as possible.
This basically creates an anchor element and simulates a Click on it…
document.addEventListener("keydown", (event) => {
if (event.key === "g") {
// Set KeyPressed to true
KeyPressed = true;
const blockEditor = document.querySelector('.editor-inner.block-editor textarea[aria-label="editing block"]');
const codeEditor = document.querySelector('.editor-inner.block-editor textarea[aria-label="editing block"]');
if (blockEditor || codeEditor) {
KeyPressed = false;
}
} else if (event.key === "h" && KeyPressed) {
// Create a new anchor element
var link = document.createElement('a');
// Generate the current date dynamically
var currentDate = new Date();
// Format the date using the custom function
var formattedDate = formatDate(currentDate);
// Construct the URL string manually (without encoding)
const url = `#/page/${formattedDate}`; // Use template literal for clarity
// Set the href attribute
link.href = url;
// Append the anchor element to the document body (or any other desired parent element)
document.body.appendChild(link);
// Simulate a click on the link
link.click();
// Reset KeyPressed to false for next key press sequence
KeyPressed = false;
}
// Function to format the date in the desired format (EEEE, dd.MM.yyyy)
function formatDate(date) {
const options = {
weekday: 'long',
day: '2-digit',
month: '2-digit',
year: 'numeric'
};
const formatter = new Intl.DateTimeFormat('en-GB', options);
return formatter.format(date).toLowerCase().replace(/\//g, '.').replace(/,/g, '%2C').replace(/ /g, "%20");
}
});
Now at least I don’t rely on Windows Task Scheduler or Powershell script and this makes my Logseq more portable.
I was somehow forced to do this quickly when my laptop broke and had to rely on a backup one and started noticing that, besides Logseq keeping folders in usershome folder on windows, I extended that issue by relying on scripts that were not OS-agnostic.
I put the code here just as an example, I still “hard-coded” the date format to match my preferences in Logseq - mainly because I don’t know how to extract it from the settings and use the one.
As I find easier or simpler ways to do this I will add them here (unless a master in js offers a one-liner to achieve all this )
Ok, this is the easiest so far but it is assuming you don’t have a default home page set in config.edn so the first thing Logseq does upon starting up is loading the Journals Page (the continously scrollable list of Journals you get when you do G J).
// If we are in Go-To-Journals then grab the Link of the first Journal displayed (presumably Today's
const todaysJournalLink = document.querySelector('.initial-color.title.journal-title');
if (todaysJournalLink && todaysJournalLink.getBoundingClientRect().top <= 0) {
todaysJournalLink.click();
const todaysJournalPage = todaysJournalLink.querySelector('h1.title').textContent;
logseq.api.set_current_graph_configs({"default-home": {"page": todaysJournalPage}})
}
This code is run when custom.js is loaded, runs one time and grabs the link and text of the first Journal’s Title and simulates a Click on it which brings you to the Current Day’s Journal. It also sets the default-home from within Logseq (internally), as per the suggestion here so that if you end up in some Page in some Block G H will bring you Home.
New code to fix the Go-To-Home to actually go to today’s journal:
// Function to perform setDefaultHome() at Logseq startup and at midnight:
function setDefaultHome() {
const query = `[
:find ?name
:in $ ?t
:where
[?p :block/journal-day ?t]
[?p :block/name ?name]
]`;
const todayJournalPage = logseq.api.datascript_query(query, ":today")[0][0];
logseq.api.set_current_graph_configs({"default-home": {"page": todayJournalPage}});
logseq.api.push_state('page', { name: todayJournalPage });
}
// Run once when Logseq starts
setDefaultHome();
// Function to calculate the time until midnight
function timeUntilMidnight() {
const now = new Date();
const midnight = new Date();
midnight.setHours(24, 0, 0, 0); // Set to next midnight
// Calculate the difference in milliseconds
const timeUntilMidnightMs = midnight - now;
return timeUntilMidnightMs;
}
setTimeout(setDefaultHome, timeUntilMidnight());
Thanks to @mentaloid for answering many newbie questions.
I am glad to see that @FlorianF was able to find some success.
But I would like to restate that I think “today” should still have its own status separate from “journal’s today”.
Besides the obvious usage of setting home=today, there would also be the option to set a bespoke shortcut in the custom.css file, something like:
In my opinion, it undermines the whole effort of starting with a clean page.
I know I can click away, but my only request this whole time has been to default to Today with nothing else.
Thanks again; I really have appreciated the work you have put in.
I’m glad I could be of help. Thank you for the many pizzas. I said adding it as an option, but there is a change. I will give you the code to remove the button by adding a line to custom.css.
#cancel-exclude {display:none} /* Single journal plugin remove the button */
Do you know how to edit custom.css?
Toolbar [・・・] > Settings > Edit custom.css
If you have any suggestions regarding Journals, I will consider whether they are feasible.