KevinBatdorf / obsidian-raycast

Raycast extension with commands for the note taking app Obsidian.
MIT License
106 stars 19 forks source link

Correct way to access Obsidian Vault on iCloud Drive? #10

Closed yodatucker closed 2 years ago

yodatucker commented 2 years ago

Having difficulty using Obsidian extension with Vault on iCloud drive. Installed Obsidian via IOS and MACOS according to Obsidian instructions to use iCloud as sync mechanism. Obsidian works properly on both platforms, changes made via either sync properly to the other.

First time running Obsidian extension, no matter how I format the path to Vault, the "Something went wrong" error pops up. Have tried formatting the path to the iCloud Vault in various ways ( /Users/xxx/Library/Mobile Documents/iCloud~md~obsidian/ ), etc.

Not sure if it's a formatting problem on my part or an issue accessing iCloud vaults

marcjulianschwarz commented 2 years ago

Hmm. I am using iCloud sync with Obsidian too and it’s working for me. Could you send me the path again without markdown format? You could do this by adding three backticks: ``` on both sides of the path.

Maybe your username (the xxx part) has invalid characters? I am using commas to split multiple paths. This means commas are not allowed in a path.

Did you try all 3 commands with this path?

yodatucker commented 2 years ago

I've got it working.

The path was as follows /Users/xxx/Library/Mobile Documents/iCloud~md~obsidian/Documents/Master Vault

Username has no special characters. Only a single vault in use. There is a space in the vault name.

Formatting error on my part. After "Master Vault" I had not terminated the path with a Slash character.

Re-entering the path as /Users/xxx/Library/Mobile Documents/iCloud~md~obsidian/Documents/Master Vault/ solved the problem.

The way I discovered this was the Open Vault and Search Note Commands worked properly. The Create Note Command still came up with the something is wrong error. I looked at the preferences for the Create Note command, and put a slash character in the "default path to note" field. The command then worked. I thought perhaps the path to vault needed to be terminated with a slash. This corrected the problem.

Still new to this, and learning every day! Thanks for the speedy response!

Thank you for a great extension!

marcjulianschwarz commented 2 years ago

Thanks for trying.

This should be fixed with the next version. Usually you shouldn't need to add a / at the end for it to work. But as you said, adding it is a quick workaround.

gwenwindflower commented 2 years ago

Not sure if i should open a separate issue quite yet since i'm seeing similar issues, only Create Note is not working for me, i'm just specifying a local vault in my Documents though, I've tried with and without a final slash and a Create Note errors out, everything else works though.

marcjulianschwarz commented 2 years ago

Hmm, I just looked at the code and I don't think the issue has anything to do with the existence of a trailing slash. On my machine everything is working even though my vault is stored in iCloud and its name has a space in it and I don't use a trailing slash.

@gwenwindflower could you please share the path/s that you used?

anosognosia commented 2 years ago

using raycast to copy the search for the vault and copy its path, I was getting /System/Volumes/Data tacked onto the front of /Users/edgar/Library/Mobile Documents/iCloud~md~obsidian/Documents/m1vault this was causing me to be able to search for notes, but would receive an error if I tried to open them. removing the first part fixed and adding the trailing the slash fixed that.

@gwenwindflower have you added a path in the "Create Note" command (in addition to adding it to the extension itself? I was getting an error until I added that

Screen Shot 2022-02-05 at 12 28 12 AM

.

@marcjulianschwarz and thank you for this amazing extension, having a systemwide search with real-time autofill is unbelievable <3

marcjulianschwarz commented 2 years ago

@anosognosia thank you for the kind words at the end!

I think you misunderstood the purpose of Default Path in the Create Note command. This path is only there to provide a default value for a subfolder in your vault. Lets say your vault is located at Users/xxx/Documents/My Vault. Then you can specify a default path in the Create Note command, for example University Notes/Module X. If you do this, every note that you create with the command will be written to Users/xxx/Documents/My Vault/University Notes/Module X.

That's why you shouldn't enter your whole path in the Default Path field. The only place where you need to specify the path to your vault is in the extensions settings and not in the commands settings.

@gwenwindflower, @yodatucker , this might be the problem that you are seeing too.

anosognosia commented 2 years ago

@marcjulianschwarz thanks for clarifying that 🙏

I had initially left it blank, but raycast was giving me an error when I ran the command, and pasting in the full path seemed to get rid of the error. but now I've deleted that Default Path in Create Note and the error is gone.

marcjulianschwarz commented 2 years ago

no problem.

However it’s still weird that it didn’t work in the beginning. Could you maybe try to reinstall the extension and let me know whether it works when only specifying the path in the extensions settings? Just to make sure that there are no errors when you leave the default path field blank.

if that works, try to add a default path and use the create note command.

If that’s working I would close this issue as I think that the confusion between default path and vault path was the problem here.

marcjulianschwarz commented 2 years ago

In a new release I will add better error logging to more easily tell where the error occurred. Will let you all know when that’s out.

anosognosia commented 2 years ago

after a reinstall, and only filling in the vault path, open vault and search note work as expected, but create note gives me the following error:

TypeError: Cannot read properties of undefined (reading 'toLowerCase')

createnote.js:4:610

---
1: var T=Object.create;var f=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var m=e=>f(e,"__esModule",{value:!0});var S=(e,n)=>{for(var r in n)f(e,r,{get:n[r],enumerable:!0})},p=(e,n,r,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of F(n))!A.call(e,a)&&(r||a!=="default")&&f(e,a,{get:()=>n[a],enumerable:!(l=k(n,a))||l.enumerable});return e},h=(e,n)=>p(m(f(e!=null?T(w(e)):{},"default",!n&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),V=(e=>(n,r)=>e&&e.get(n)||(r=p(m({}),n,1),e&&e.set(n,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var L={};S(L,{default:()=>d});var t=require("@raycast/api"),g=h(require("fs")),u=h(require("path"));function N(e){let n=e.split(u.default.sep).filter(r=>{if(r!="")return r}).pop();return n||"Default Vault Name (check your path preferences)"}function x(){return(0,t.getPreferenceValues)().vaultPath.split(",").map(r=>({name:N(r.trim()),key:r.trim(),path:r.trim()})).filter(r=>!!r)}function C(){let n=(0,t.getPreferenceValues)().prefPath;return n||""}function b(){let n=(0,t.getPreferenceValues)().prefTag;return n?[n]:[]}function j(){let e=(0,t.getPreferenceValues)(),n=e.tags,r=e.prefTag;if(!n)return[{name:r,key:r}];let l=n.split(",").map(a=>({name:a.trim(),key:a.trim()})).filter(a=>!!a);return l.push({name:r,key:r}),l}function y(e){let n=e.vaultPath,{pop:r}=(0,t.useNavigation)();async function l(i,o,s){if(g.default.existsSync(u.default.join(i,o+".md"))){let c={title:"Override note",message:'Are you sure you want to override the note: "'+o+'"?',icon:t.Icon.ExclamationMark};await(0,t.confirmAlert)(c)&&a(i,o,s)}else a(i,o,s)}function a(i,o,s){try{g.default.mkdirSync(i,{recursive:!0}),g.default.writeFileSync(u.default.join(i,o+".md"),s),(0,t.showToast)(t.ToastStyle.Success,"Created new note"),r()}catch{(0,t.showToast)(t.ToastStyle.Failure,"Something went wrong. Maybe your vault, path or filename is not valid.")}}function P(i,o){let s="";if(i.length>0){s=`---
2: tags: [`;for(let c=0;c<i.length-1;c++)s+='"'+i[c]+'",';s+='"'+i.pop()+`"]
3: ---
4: `}return s+=o,s}function v(i){if(i.name=="")(0,t.showToast)(t.ToastStyle.Failure,"Please enter a name");else{let o=P(i.tags,i.content);l(u.default.join(n,i.path),i.name,o)}}return _jsx(t.Form,{navigationTitle:"Create new Note",actions:_jsx(t.ActionPanel,null,_jsx(t.SubmitFormAction,{title:"Create",onSubmit:v}))},_jsx(t.Form.TextField,{title:"Name",id:"name",placeholder:"Name of note"}),_jsx(t.Form.TextField,{title:"Path",id:"path",defaultValue:C(),placeholder:"path/to/note (optional)"}),_jsx(t.Form.TagPicker,{id:"tags",title:"Tags",defaultValue:b()},j()?.map(i=>_jsx(t.Form.TagPicker.Item,{value:i.name.toLowerCase(),title:i.name,key:i.key}))),_jsx(t.Form.TextArea,{title:"Content:",id:"content",placeholder:"Text"}))}function I(e){let n=e.vaults;return _jsx(t.List,null,n?.map(r=>_jsx(t.List.Item,{title:r.name,key:r.key,actions:_jsx(t.ActionPanel,null,_jsx(t.PushAction,{title:"Select Vault",target:_jsx(y,{vaultPath:r.path})}))})))}function d(){let e=x();if(e.length>1)return _jsx(I,{vaults:e});if(e.length==1)return _jsx(y,{vaultPath:e[0].path});(0,t.showToast)(t.ToastStyle.Failure,"Path Error","Something went wrong with your vault path.")}module.exports=V(L);0&&(module.exports={});
5: 
---

    at Array.map (<anonymous>)
y:createnote.js:4:562
wl:react-reconciler.production.min.js:5:19061
Wi:react-reconciler.production.min.js:9:6962
ji:react-reconciler.production.min.js:9:940
Jo:react-reconciler.production.min.js:9:871
Ut:react-reconciler.production.min.js:9:728
Jl:react-reconciler.production.min.js:7:12492
react-reconciler.production.min.js:5:4358

this goes away if I enter / in the default path, and will continue to function even if I delete the slash afterwards

marcjulianschwarz commented 2 years ago

Thank you so much for your help and for sharing the error message!

This has to be fixed, I will look at it right now although I will most likely not be able to get it done until tomorrow as it’s already quite late for me.

anosognosia commented 2 years ago

my pleasure, thanks for all your hard work!

and @gwenwindflower seems like the workaround for create note is just to add a / in the command's default path

marcjulianschwarz commented 2 years ago

I just found the part that was throwing the error. It actually has nothing to do with the path or default path that has been set.

In the Create Note command settings you can set a Default Tag which will be automatically selected when using the command. When you first install the extension this field will be empty. Now in the code I will read that value and somehow it doesn't return an empty string like this "" but it returns undefined which is the reason that the following code will crash. By going into the commands settings and changing any value there, will result in the default values being converted from undefined to empty strings "". That's why the command worked when you changed the Default Path setting to /. You could however set it to anything you want or only set one of the other settings.

To fix this error I am now testing whether the settings are undefined before using them anywhere. I will push this ASAP because I would call it a major bug. For now, changing/updating/setting the commands settings will be a quick workaround.

I will let you all know when the fix has been released. Again, thank you all for making me aware of this problem.

marcjulianschwarz commented 2 years ago

Should be fixed with commit 6ee1abf27658139cb46c0f190368e5d057d214ed.

yodatucker commented 2 years ago

Just to add a bit of help here. Extension was working properly. Only configuration info is Path to Vault in extension, /Users/steve/Library/Mobile Documents/iCloud~md~obsidian/Documents/Master Vault nothing in create note configuration. Copied Extension configuration to Clipboard. Uninstalled extension.

Reinstalled extension. Ran Create Note command for first time. Pasted in Path to Vault from above. Double checked it was the same. Pressed Return and "Something went wrong" Error popped up. Open Vault command located and opened the only vault. Search Vault Command errored out with "Directory not found" error. Opened Extension preferences, Create note Preferences and added slash to Default Directory field. "Something Went Wrong" again popped up.

Disabled extension and then re-enabled. "Something went wrong" error disappeared and Create note entry box popped up ok, but the new notes were created on the local drive in a location formatted similar to iCloud Drive but not in the iCloud obsidian vault! Search Notes only shows 3 test notes and nothing in iCloud Obsidian Vault.

image

Deleted extension. Reinstalled. Went directly to Extension preferences prior to running any command and pasted in Path to Vault as a done previously. Create Note errored out as above on first time run. Added slash character to Default Path in Create Note config. Create Note command now works properly and points to proper iCloud Vault.

I seem to recall at one point that disabling the extension and re-enabling it also changed the error at one point. I'm sorry, I forgot to document the exact point this happened.

It seems that if I run the extension for the first time with no configuration info and it asks for Path to Vault on first time run, that it's almost impossible for me to get the extension to run properly. However, if I install the extension, do not run any command, but go into the configuration for the extension and put in the default path to vault, then go to the Create Note configuration in the Default Path to Note and enter a slash character, the command will then work and point to the proper vault. I can then delete the slash character from the Create Note Default Path to Note and it will continue to work properly.

Very strange, as I had it working fine, but deleting and reinstalling had me jumping through hoops again! When it is working, however, it's a fantastic extension. Hope this helps!

yodatucker commented 2 years ago

Above comment was written as developer was committing fix. May no longer be applicable.

marcjulianschwarz commented 2 years ago

@yodatucker thank you very much for this detailed explanation.

I think you might want to try out the new release when it is ready. It will most likely fix the problem where the Create Note command wasn't working without prior configuration.

However, the first problem you mentioned (shown in your image) is still very strange. Maybe you can share your correct iCloud path in the finder (as you did in the image)? You can contact me at one of the accounts listed on my website here if you would want to share it privately.

Did the extension throw an error message that looked like this?

Bildschirmfoto 2022-02-06 um 08 47 19

If yes, then could you please press cmd+K to then copy the error message in the menu that pops up and share it here? That would help a lot in trying to reproduce/understand the problems you are facing.

GrantGochnauer commented 2 years ago

Hello -

I just ran into the same issue. My vault path in Raycast is: /Users/grant.gochnauer/Library/Mobile Documents/iCloud~md~obsidian/Documents/Grant/ and then when I hit Create Note, I get this error:

TypeError: Cannot read properties of undefined (reading 'toLowerCase')

createnote.js:4:610

---
1: var T=Object.create;var f=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var m=e=>f(e,"__esModule",{value:!0});var S=(e,n)=>{for(var r in n)f(e,r,{get:n[r],enumerable:!0})},p=(e,n,r,l)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of F(n))!A.call(e,a)&&(r||a!=="default")&&f(e,a,{get:()=>n[a],enumerable:!(l=k(n,a))||l.enumerable});return e},h=(e,n)=>p(m(f(e!=null?T(w(e)):{},"default",!n&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),V=(e=>(n,r)=>e&&e.get(n)||(r=p(m({}),n,1),e&&e.set(n,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var L={};S(L,{default:()=>d});var t=require("@raycast/api"),g=h(require("fs")),u=h(require("path"));function N(e){let n=e.split(u.default.sep).filter(r=>{if(r!="")return r}).pop();return n||"Default Vault Name (check your path preferences)"}function x(){return(0,t.getPreferenceValues)().vaultPath.split(",").map(r=>({name:N(r.trim()),key:r.trim(),path:r.trim()})).filter(r=>!!r)}function C(){let n=(0,t.getPreferenceValues)().prefPath;return n||""}function b(){let n=(0,t.getPreferenceValues)().prefTag;return n?[n]:[]}function j(){let e=(0,t.getPreferenceValues)(),n=e.tags,r=e.prefTag;if(!n)return[{name:r,key:r}];let l=n.split(",").map(a=>({name:a.trim(),key:a.trim()})).filter(a=>!!a);return l.push({name:r,key:r}),l}function y(e){let n=e.vaultPath,{pop:r}=(0,t.useNavigation)();async function l(i,o,s){if(g.default.existsSync(u.default.join(i,o+".md"))){let c={title:"Override note",message:'Are you sure you want to override the note: "'+o+'"?',icon:t.Icon.ExclamationMark};await(0,t.confirmAlert)(c)&&a(i,o,s)}else a(i,o,s)}function a(i,o,s){try{g.default.mkdirSync(i,{recursive:!0}),g.default.writeFileSync(u.default.join(i,o+".md"),s),(0,t.showToast)(t.ToastStyle.Success,"Created new note"),r()}catch{(0,t.showToast)(t.ToastStyle.Failure,"Something went wrong. Maybe your vault, path or filename is not valid.")}}function P(i,o){let s="";if(i.length>0){s=`---
2: tags: [`;for(let c=0;c<i.length-1;c++)s+='"'+i[c]+'",';s+='"'+i.pop()+`"]
3: ---
4: `}return s+=o,s}function v(i){if(i.name=="")(0,t.showToast)(t.ToastStyle.Failure,"Please enter a name");else{let o=P(i.tags,i.content);l(u.default.join(n,i.path),i.name,o)}}return _jsx(t.Form,{navigationTitle:"Create new Note",actions:_jsx(t.ActionPanel,null,_jsx(t.SubmitFormAction,{title:"Create",onSubmit:v}))},_jsx(t.Form.TextField,{title:"Name",id:"name",placeholder:"Name of note"}),_jsx(t.Form.TextField,{title:"Path",id:"path",defaultValue:C(),placeholder:"path/to/note (optional)"}),_jsx(t.Form.TagPicker,{id:"tags",title:"Tags",defaultValue:b()},j()?.map(i=>_jsx(t.Form.TagPicker.Item,{value:i.name.toLowerCase(),title:i.name,key:i.key}))),_jsx(t.Form.TextArea,{title:"Content:",id:"content",placeholder:"Text"}))}function I(e){let n=e.vaults;return _jsx(t.List,null,n?.map(r=>_jsx(t.List.Item,{title:r.name,key:r.key,actions:_jsx(t.ActionPanel,null,_jsx(t.PushAction,{title:"Select Vault",target:_jsx(y,{vaultPath:r.path})}))})))}function d(){let e=x();if(e.length>1)return _jsx(I,{vaults:e});if(e.length==1)return _jsx(y,{vaultPath:e[0].path});(0,t.showToast)(t.ToastStyle.Failure,"Path Error","Something went wrong with your vault path.")}module.exports=V(L);0&&(module.exports={});
5: 
---

    at Array.map (<anonymous>)
y:createnote.js:4:562
wl:react-reconciler.production.min.js:5:19061
Wi:react-reconciler.production.min.js:9:6962
ji:react-reconciler.production.min.js:9:940
Jo:react-reconciler.production.min.js:9:871
Ut:react-reconciler.production.min.js:9:728
Jl:react-reconciler.production.min.js:7:12492
react-reconciler.production.min.js:5:4358
marcjulianschwarz commented 2 years ago

Hello @GrantGochnauer. Thank you for letting me know.

This error should be fixed with the new version, which has already been approved. It will be merged soon. I will let you know when it has been published to the store.

marcjulianschwarz commented 2 years ago

As it turns out the update has just been released to the store. 🔥

You can install the extension here or update it in the Raycast Store.

Closing this issue now, feel free to reopen it when necessary.

gwenwindflower commented 2 years ago

working for me now as well, sorry been super hectic the past week, apologies i wasn't more helpful with error details, thank you so much for the fix! 🙏🏻

marcjulianschwarz commented 2 years ago

@gwenwindflower no problem at all. Happy that I got it fixed.

stashev commented 2 months ago

I've just installed the recent extension and still getting error on search or creating notes