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?

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)?

1 Like

I actually tunred this into a Feature Reqest after skinnming through GitHub to see no such request (only some Closed ones that were kind of related)

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.

In custom.js, it is possible to:

  • get today’s date with var today = new Date()
  • format the date into the name of the page
    • Depending on the complexity, may need something as ugly as DateTimeFormat:
      var pageName = Intl.DateTimeFormat(locale, options).format(today)
    • Simple formats are much easier.
  • navigate to the page with window.location.href = '#/page/' + pageName
    • if the name contains special characters, encode it with encodeURIComponent(pageName)
    • failing to provide a valid name may mess the application
1 Like

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::

  1. 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;
  2. 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

and the Shortcut File looks like:

Now use this file to open Logseq (by addingit to the startup folder, for example);

My daily journal looks like this:

and with the above setup I can use G H to get to this:

Like I said, Logseq deosn’t like having two files within its graph having the same name, that’s why I ended up with “(today)” added to the name.

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