GithubHelp home page GithubHelp logo

marlon154 / obsidian-python-scripter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nickrallison/obsidian-python-scripter

0.0 0.0 0.0 71 KB

License: GNU General Public License v3.0

JavaScript 21.48% TypeScript 76.32% CSS 2.20%

obsidian-python-scripter's Introduction

Obsidian Python Scripter

Summary

This is a program to quickly allow you to run your own Python scripts from inside Obsidian. To get started enable this plugin, it will create a scripts/python folder inside your designated .obsidian folder. For each script it will add a custom command to the obsidian commands panel.

Requirements

  • Install your preferred version of python and make sure it functions from the command line eg: python .obsidian/scripts/python/main.py
  • This plugin works with naked python scripts eg. scripts/python/example.py
  • Or you may want a more complicated script, you can have a folder as a script. You just need to have a main.py file inside of a src folder for it to function as a command, otherwise it will not be able to execute. Make sure to structure the scripts/python as follows
  scripts
    |
    ---- python
           |
           ---- example
                  |
                  ---- src
                        |
                        ---- main.py
                        |
                        ---- hello.py

Your resulting scripts folder should have a structure like the following:

  scripts
    | 
    ---- python
           | 
           ---- example 
           |       | 
           |       ---- src 
           |             | 
           |             ---- main.py 
           |             | 
           |             ---- hello.py 
           | 
           ---- example2.py 

Obsidian Directions

  • Add your python scripts in the format specified in the requirements section.
  • Once Obsidian starts, your commands will be added to the commands window and can be run as you would like.
  • If Obsidian is already open it will need to be Restarted when first added but not after that
  • In the above example, there would be 2 commands added:
    • Run example
    • Run example2.py

commandwindow

Script Direction

The script passes 2 arguments to the script, argument 1 is the absolute path to the obsidian root folder, argument 2 is the path to the open file if it is open, otherwise an empty path is sent e.g. python \Users\nick\Documents\Vault\.obsidian\scripts\python\main.py \Users\nick\Documents\Vault dir1\file1.md

These can be used by the script as liked.

Here is a starting point for a python script: main.py

# main.py
import sys
import os

python_script = sys.argv[0]
file_path = sys.argv[2]
vault_path = sys.argv[1]

abs_file_path = os.path.abspath(os.path.join(vault_path, file_path))

print(f"This is the open file: {abs_file_path}")

Settings

You have the ability to change the python script location in settings. Additionally you have the ability to change which python executable is used.

Debugging

If your script fails to run. An error is shown in the top right of obsidian and in the developer console which can be found with the following hotkeys: "ctrl" + "shift" + "i" on Windows, or "cmd" + "option" + "i" on MacOS

obsidian-python-scripter's People

Contributors

nickrallison avatar marlon154 avatar incarnadined avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.