espanso / espanso

Cross-platform Text Expander written in Rust
https://espanso.org
GNU General Public License v3.0
10.09k stars 278 forks source link

Using Script Matches on Windows and MacOS crossplatform? #262

Closed alexander-seidl closed 4 years ago

alexander-seidl commented 4 years ago

I tried to reimplement the following example [1] so that i can use on my Windows and MacOS Machine. The crucial point ist the second arg: "/path/to/your/script.py". What can i do to make it run on both machines? Python is properly installed on both machines. I need some dynamic replacement here that replaces "root" accordingly for Mac and Windows. How can i do this?

macos root: /root/ windows root: C:\root\

path = root + script.py

[1] script.py: print("Hello from python")

- trigger: ":pyscript"
  replace: "{{output}}"
  vars:
    - name: output
      type: script
      params:
        args:
          - python
          - /path/to/your/script.py
alexander-seidl commented 4 years ago

Maybe, i can access an envionment variable in a platform independent way. @CONFIG, that was indroduced with expanding images does not work here.

federico-terzi commented 4 years ago

Hey, I opened another issue for the same purpose without noticing! To keep only one of them I'll close this issue and move the discussion to #265 .

risjain commented 1 year ago

I tried to reimplement the following example [1] so that i can use on my Windows and MacOS Machine. The crucial point ist the second arg: "/path/to/your/script.py". What can i do to make it run on both machines? Python is properly installed on both machines. I need some dynamic replacement here that replaces "root" accordingly for Mac and Windows. How can i do this?

macos root: /root/ windows root: C:\root\

path = root + script.py

[1] script.py: print("Hello from python")

- trigger: ":pyscript"
  replace: "{{output}}"
  vars:
    - name: output
      type: script
      params:
        args:
          - python
          - /path/to/your/script.py

I was trying to do the same in order to point to the relative locations of my dotfiles given the OS, for running some scripts.

While many use-cases might be left out, this one works - sort of:

 - trigger: ":test"
    replace: "{{myshell}}"
    vars:
      - name: WHOME
        type: shell
        params:
           cmd: 'if [[ "$OSTYPE" == "darwin"* ]]; then echo $HOME; elif [[ "$OSTYPE" == "linux-gnu"* ]]; then if [[ `uname -a | grep -i linux | grep -i microsoft`  != "" ]]; then echo /path/to/your/custom/home; fi; fi'
      - name: myshell
        type: shell
        params:
          cmd: "whatever/your/command/is/using/ $ESPANSO_WHOME"

I tried sourcing the .env file in $HOME - since it will have the basic variables defined - but that didn't work. So, this is the current work around to point to the same custom scripts in both WSL and OSX.

If anyone has a better/cleaner solution - do share!