Templater
Templater copied to clipboard
Allow User Scripts on Mobile
There was an issue where if you tried to use user scripts on mobile devices, it would throw an error saying that your script did not exist. It would still detect your user scripts in the settings, but you would not be able to generate any templates. Removing the check to only allow user scripts for desktop seems to have resolved the issue.
This is working for me on my personal Android phone. I am not sure which mobile device caused this to be solely allowed for desktop prior, but it may be that Obsidian has been updated in such a way that the issue has gone away.
fix #586
Changes Made:
- Removed Platform import from Obsidian and using it to check if the current platform is desktop in
UserFunctions.ts
@SilentVoid13 , I will await your review. I am not sure how we are supposed to run the UTs since I was unable to do so by running any of the npm run ...
commands. Please let me know if you would like changes or anything like that.
Hi, I've applied this in a very sketchy way in my own Vault. I don't recommend trying this at home, cause why would you choose to patch plugins in your own Vault, it could break everything, don't do this, I will not provide support if you do this...
But, if you know what you're doing, you have backups, and your Templater version is 1.12.0, you can copy my bad idea.
Save this file as templaterUserScripts.patch
:
--- .obsidian/plugins/templater-obsidian/main.js 2022-07-12 11:33:23.000000000 +0200
+++ .obsidian/plugins/templater-obsidian/main.js 2022-07-12 11:36:19.000000000 +0200
@@ -3062,7 +3062,7 @@
if (this.plugin.settings.enable_system_commands) {
user_system_functions = yield this.user_system_functions.generate_object(config2);
}
- if (import_obsidian13.Platform.isDesktopApp && this.plugin.settings.user_scripts_folder) {
+ if (this.plugin.settings.user_scripts_folder) {
user_script_functions = yield this.user_script_functions.generate_object(config2);
}
return __spreadValues(__spreadValues({}, user_system_functions), user_script_functions);
And then run patch .obsidian/plugins/templater-obsidian/main.js < templaterUserScripts.patch
in your Vault's root directory.
Can confirm this edit works on an iPad.
I can also check on other platforms if needed.
Could we possibly get a link to the initial issue and why this was disabled?
It seems that it may have not worked in a few cases with imports or something but for things like utility functions which just wrap checking dates and most of what I use it for it works perfect.
Id rather this be enabled with the error messages than entirely remove it for those who don't need whatever cases it was erroring in. Unless it was possibly causing larger data loss somehow.
I believe this also relates to issue #550 too
merging
Thanks @shabegom!