SilentVoid13 / Templater Public
generated from obsidianmd/obsidian-sample-pluginNew issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom variables don't work on windows: they aren't being evaluated #128
Comments
|
@yhoebeke I'm guessing this is because on Windows, the default shell is PowerShell, not |
|
I am really sorry, but this may go beyond my basic coding knowledge. I also found this : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_variables?view=powershell-7.1 The error seems to come from before the command is sent to the command line. |
|
@yhoebeke See #129 ... on Windows it seems that Electron's default shell for So, your user template would need to reference the variables in "batch file" format echo %from%Or, you can use PowerShell via: powershell -command "& { Write-Host -NoNewLine ('from variable = ' + $Env:from) }" |
|
Thank you @luckman212 for the explanations!
Now I tried to combine it with the agenda code (without any variables first) and Error with User Template echo Error: Command failed: powershell -command "C:/Users/adminuser/AppData/Local/Programs/Python/Python37-32/Scripts/gcalcli agenda 2021/04/20 2021/04/21"
Traceback (most recent call last):
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\adminuser\AppData\Local\Programs\Python\Python37-32\Scripts\gcalcli.exe\__main__.py", line 7, in <module>
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\site-packages\gcalcli\cli.py", line 152, in main
gcal.AgendaQuery(start=parsed_args.start, end=parsed_args.end)
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\site-packages\gcalcli\gcal.py", line 1238, in AgendaQuery
return self._display_queried_events(start, end)
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\site-packages\gcalcli\gcal.py", line 1187, in _display_queried_events
return self._iterate_events(start, event_list, year_date=year_date)
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\site-packages\gcalcli\gcal.py", line 1056, in _iterate_events
self._PrintEvent(event, prefix)
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\site-packages\gcalcli\gcal.py", line 710, in _PrintEvent
event_color
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\site-packages\gcalcli\printer.py", line 89, in msg
file.write(msg)
File "c:\users\adminuser\appdata\local\programs\python\python37-32\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f4b0' in position 28: character maps to <undefined>
at ChildProcess.exithandler (child_process.js:312)
at ChildProcess.emit (events.js:310)
at maybeClose (internal/child_process.js:1021)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286)So I don't understand why the code that worked before, simply using cmd.exe, doesn't work anymore. Next, I tried using the powershell without variables. <% tp.user.agenda() %>powershell (C:/Users/adminuser/AppData/Local/Programs/Python/Python37-32/Scripts/gcalcli agenda --nocolor)So instead of giving me the results for the whole week, it seems the result are cut off. Next, I tried using the powershell with variables. |
|
Hey @yhoebeke as @luckman212 said, if you're using cmd you must use |
|
We shouldn't mix the syntax. How about skipping edit: so far it doesn't quite work (yet) - awaiting answer on #129 about overriding Template: user function TestFunc: refs: |
|
@yhoebeke SV confirms that setting ComSpec doesn't work (yet) but he may add a switch for that. For now, I found a temporary solution, you may want to try this: Template (example) User Function (MyFunc) |
|
Is it just me or did my last message here disappear? |
|
I think it's just you, what was the message about? |
|
I had written a long message last evening explaining some debugging I had done with quite some screenshots (I guess there might have been a bug when submitting my comment). The bottom-line of my message was that I found two (I think related) issues:
@SilentVoid13 So in the end, perhaps there is a problem in how powershell returns/encodes certain characters and/or how templater processes certain characters and emojies ? To replicate, try asking for your agenda with this command |
|
Hey @yhoebeke, this is a know problem with powershell, that does not come from Templater (re #9 #15). |




Plugin informations (please complete the following information):
Describe the bug
It looks like the variables aren’t getting evaluated when a user function is called.
Expected behavior
user-defined variables in custom function calls should be evaluated accordingly.
The code that made me find this error can be found here : Adding your google calendar agenda to your daily journal - Share & showcase - Obsidian Forum
I wasn't able to make the code work as the variables $from $to weren't replaced by the correct values.
Screenshots



This user function:
Returns this
The text was updated successfully, but these errors were encountered: