Zettelkasten Forum


Change header tags into Mac OS tags

Hello!

Right now, my tags are included in the header of the notes

---
Tags: #Anytag 
Date:
---

To navigate my files, I create manually SmartFolders with the condition "Content includes #Anytag" for each tag. This is a bit cumbersome as it forces me to add a new SmartFolder each time I add a new tag, and I don't have a simple view of all existing tags.

I was wondering if any of you knew how to "synchronize" those tags with Mac OS tags? That would be really nice to easily navigate my zettelkasten!

Comments

  • @tantrig I suspect there is a way to do what you want in Keyboard Maestro, but I'm just learning how to use that program and can't say for sure. @Will has much more knowledge and experience with Keyboard Maestro and might comment on its capabilities.

    @Will does have a KM macro that creates and then updates a note in The Archive containing a list of all of your tags. This might get you part way towards your goal. I can't seem to find the post on that at the moment.

  • Very interesting, this looks like exactly what I need. Do you know if the synchronization also deletes tags when they are removed from the note's header?

  • I just remembered the discussion and thought it may be helpful to you.

    Reach out tho the developer, @zisoft, as he posted the link to his github repository.

    Or perhaps he may reply or someone who uses the script.

  • @tantrig said:
    Very interesting, this looks like exactly what I need. Do you know if the synchronization also deletes tags when they are removed from the note's header?

    @tantrig: Yes, it does! :smile:

    The tags are in fact synchronized: You can add, delete or modify tags.

  • @tantrig: Yes, it does! :smile:

    The tags are in fact synchronized: You can add, delete or modify tags.

    @zisoft - I dowloaded the files from github, modified the *.plist file as instructed, loaded it, and made the *.rb file executable (I think; I'm not sure how to check if the command entered into terminal is "working").

    I then loaded the test.md file into my Zettelkasten and made some changes to the tags - it appears nothing is happening, i.e., I don't see the tags showing up for the file when I check with "Get Info" in the finder. I can see the text of the file has changed (in Preview) but I see no Finder tags.

    Any suggestions?

  • edited September 20

    Several things may fail here, so make a few checks:

    Check if the openmeta binary is installed at the expected location: /usr/local/bin/openmeta.
    If this is true then modify a md file to give it a current timestamp, open the terminal, change to the directory where your md files are located and run the script manually (the following example assumes you have installed mdtags.rb in your home folder "scripts" directory):

    cd path_to_your_markdown_files
    ~/scripts/mdtags.rb

    Now check if the tags have been assigned.
    If this is true, there is most probably something wrong with launchd. Make sure you have installed mdtags.rb in an executable location (i.e. ~/scripts). Do not put the script in a iCloud drive folder, launchd will not execute it there.

    Double check the path settings in the plist file.

  • @zisoft said:
    Several things may fail here, so make a few checks:

    Check if the openmeta binary is installed at the expected location: /usr/local/bin/openmeta.

    I don't see any mention of openmeta in the referenced directory (see file listing).

    Is this something that normally gets installed with python or with some other software? I tried using the Apple search for "openmeta" and googling "how to install openmeta binary" but didn't really find anything useful. Can you suggest why it's apparently missing or how to install it?

    Thanks.....John

  • edited September 21

    I tried using this script but had the same issue, nothing happened when I modified a .md file in the folder and I don't have any openmeta forlder.

    Other question: does the script works with subfolders too?

  • Ok, you caught me here :smile:

    I have installed openmeta so many years ago that I thaught it was part of MacOS, which in fact is not.

    The "official" way to read/write tags on MacOS is xattr, which is cumbersome to use on the command line, but that doesn't matter when using in a script. I will change the script to use xattr and remove the dependency on openmeta.

    However, if you don't want to wait a few days you can install openmeta from here: https://code.google.com/archive/p/openmeta/

    Just install it in /usr/local/bin or wherever you like. If you change the location you need to update the path in mdtags.rb.

    @tantrig: I will update the script to work recursively on subdirectories as well.

  • Thank you for your help! However, when running openmeta, I get the following error
    (base) user@MacBook-Pro ~ % /Users/user/Library/Mobile\Documents/com\~apple\~CloudDocs/Téléchargements/openmeta ; exit; zsh: bad CPU type in executable: /Users/user/Library/MobileDocuments/com~apple~CloudDocs/Téléchargements/openmeta

  • Sorry I cannot help with openmeta but you can try to install it in a non-iCloud drive folder. Apple has special permission restriction on iCloud drive folders.

    Just give me a few days to update my script :-)

  • I think openmeta doesn't work with Catalina because of the lack of support of 32bits app... But great to know you are working on the script, thank you so much for your help!

  • Done, openmeta is no longer required. The tags are now written the "official" way using xattr.

    The specified directory is processed recursively, all subfolders are included.

    Please re-download from my github repository: https://github.com/zisoft/mdtags and let me know if there are any further issues.

  • @zisoft said:
    Done, openmeta is no longer required. The tags are now written the "official" way using xattr.

    The specified directory is processed recursively, all subfolders are included.

    Thank you! Will do.

  • @zisoft Works perfectly - thank you!!

  • Thank you so much great work! Only thing: it seems like the script doesn't work when my note folder is in Documents, probably because of some iCloud Drive problem. Do you think this could be solved or should I just use another sync service?

  • With macOS Mojave Apple added yet another security measure. Applications requiring access to sensitive data need special permissions beyond Unix permissions and ACLs.

    See the FAQ here: https://www.soma-zone.com/LaunchControl/FAQ.html "How do I grant Full Disk Access to my script on macOS Mojave and newer?"

    Personally I find Apples iCloud Drive implementation a horrible solution for command line tools and scripting. Dropbox is much better integrated for that.

  • Thank you!

    I tried running the script with Launchcontrol after allowing the program and adding this fdautil function but I get an "error 1". I'm not sure why, do you know how I could solve this? I checked and I changed the scripts with the adequate path to my note folder and to the mdtags.rb file (located in users/script, so not in iCloud Drive).

    Regarding iCloud Drive, I use it because it allows to import and sync folders in app on iOS such as iA Writer. With Google Drive, for example, I need to constantly import and export files from an app, which is just a huge waste of time and of organization. So I'm staying on iCloud Drive for now

  • edited September 24

    In LaunchControl set StandardOutPath and StandardErrorPath to files in your home directory. Then launch the script and check the contents of these files for possible error messages.

    Please let me know whats going wrong.

  • @tantrig I use The Archive and iA Writer to process notes for my ZK. They both "play" nicely with Dropbox, so I purposefully avoid the iCloud drive. I've been able to run @zisoft's revised script without a problem when the referenced folder is in Dropbox. It might be time to consider migrating your ZK folder?

  • I just made some further tests, everything works fine even if the notes folder is in iCloud drive. But you need to use fdautil to give the script the required permissions for iCloud.

  • edited September 25

    I installed fdautil using Launchercontrol but to save the modified script I need the paid version. Is there a way to use fdautil without launchercontrol? Which line should I modify? Thanks again for your help!

    I get the following error when running the scrip with fdautil (through Launchcontrol)

    shell-init: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
    job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
    job-working-directory: error retrieving current directory: getcwd: cannot access parent directories: Operation not permitted
    /Users/myusername/Scripts/mdtags.rb:20:in `glob': Operation not permitted -  (Errno::EPERM)
        from /Users/myusername/Scripts/mdtags.rb:20:in `<main>'
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
    

    (I replaced my actual username by myusername for anonymity)

    EDIT: it finally worked! After installing fdautil with Launchcontrol, I modified the plist file as such:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Disabled</key>
        <false/>
        <key>EnvironmentVariables</key>
        <dict>
            <key>LANG</key>
            <string>en_US.UTF-8</string>
        </dict>
        <key>Label</key>
        <string>de.zisoft.mdtags</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/fdautil</string>
            <string>exec</string>
            <string>/Users/user/Scripts/mdtags.rb</string>
        </array>
        <key>WatchPaths</key>
        <array>
            <string>/Users/raphaelhuleux/Documents/Notes</string>
        </array>
        <key>WorkingDirectory</key>
        <string>/Users/user/Documents/Notes</string>
    </dict>
    </plist>
    
    Post edited by tantrig on
  • Great to hear that!

Sign In or Register to comment.