Scriptable on iOS is so good. I’m building out an Obsidian library in JavaScript and there is just so much there.

Got my initial library up. Was able to append text to a header section.

Next up: geolocation links that integrate with the MapView plugin.

Who knew Scriptable was so good?

#obsidian #javascript #scriptable #ios

@rob I’m intrigued to hear more about this.

Let's start with the baseline: iOS shortcuts are great and they are terrible. They are great because they are so powerful, but they give a terrible user experience both when programming (the Shortcuts UI is so bad) and also at run time, depending on the shortcut. For instance, I purchased Actions for Obsidian and while they work great, the fact that it opens Obsidian and shortcuts and whatever else made it a non-starter for me.

@cctechwiz

There are a number of iOS tools that will allow you to post to your vault and aggregate data, but none of them give you very much control.

@cctechwiz

@rob I have the same issue with Actions for Obsidian (and iOS shortcuts in general). It’s so jarring to have it bounce back and forth between 3 apps for like 5 seconds whenever I want to save a snippet or capture an idea. Not to mention how painfully slow it feels (as a software engineer) to build shortcuts with the UI.

I think Actions for Obsidian isn't as terrible on the Mac. But I don't have a Mac, so it's not good software for me.

Glad I'm not the only one!

@cctechwiz

@rob Yea the Mac version is good. But I do most of my article reading on my phone while I’m just sitting around waiting for things so I never really use the Mac versions.

Scriptable gives you the headless shortcuts runs, has access to a lot of the iPhone, and is all wrapped in a Javascript library.

So far, I have written the following objects:

* ObsidianFile
* FrontMatter
* Section
* ObsidianNote (subclass of ObsidianFile)

I have about 30 methods. And what I have really tested is to see if I could write text to the end of a section (I can). So now I have to circle back and test the other methods.

@cctechwiz

@rob Oh interesting. Are you working with the md files directly then?

I'll put the code out on GIT as soon as I've had some time to test more of it.

There is a little complexity in passing parameters to Scriptable, but it seems very doable.

Is there anything specific you want to do? My ideas going forward (because of the Scriptable libraries) are:

* Geolink class (to be used with the MapView plugin)
* Calendar import from iOS into a note
* Contacts class (pull contacts from iOS into a note) (this is low priority)

https://docs.scriptable.app

@cctechwiz

Scriptable Docs - Scriptable Docs

Documentation for Scriptable, an automation app for iOS.

@rob I’ve been trying to track more of my habits and routines in Obsidian. I’ve currently got a Shortcut that is a picker I’ve got bound to my action button. But like we’ve already discussed it’s super jarring sometimes using Actions for Obsidian. Also everything has to append to the end and I have to fix it myself later.

@cctechwiz

Does this shortcut do anything like create a file from a template if one doesn’t exist? Because this isn’t there yet. It can create a file from scratch if it doesn’t exist, but all the text has to be either created at runtime or - of you have a complicated template - you’d have to write the JavaScript to process it at runtime.

@cctechwiz

I’m not a heavy template user which is why I haven’t focused on that area of the code. However, that’s why there is an ObsidianFile object: to create a base class for Obsidian File Types.

@cctechwiz

This shortcut writes a note to the Quick Capture folder and only uses native iOS functionality. The shortcut takes forever to finish because location is a very expensive process. But all that happens after you’ve sent the data.

https://www.icloud.com/shortcuts/e780bbb0ed744a03b197e00ea52b087c

Shortcuts

@cctechwiz

I wrote a base shortcut that is called by the first one. The text is split into 2 parts: the subject (first line) and the body (second line and everything else).

You can do a lot with this split text: send an email, create a calendar entry, create an obsidian file name (subject) and text (body), etc. etc.

https://www.icloud.com/shortcuts/3814b5e008904c478171163add939850

Shortcuts

@cctechwiz

Here’s the point, even if you don’t download these shortcuts. Scriptable needs explicit file access to read files. iOS shortcuts do not. So the path forward is either read/write via iOS shortcuts and process in Scriptable or grant that access and do everything in Scriptable.

@rob Interesting. That’s really go to know. I’ll play with those shortcuts and scriptable. I’m just excited to have a new tool in my arsenal now. Thanks.

@cctechwiz

You make any progress? I have a simple object model written now for the following objects:

- ObsidianFile
- FrontMatter
- Section
- Sections
- ObsidianNote (extends Obsidian file)

I have tested creating a file, appending front matter, creating a section (starts with # 1-6) and appending or prepending text to a section. Just a couple of lines of code can create a very robust note.

Next up: calendar objects to write my daily calendar to my notes.

@cctechwiz
I’ve got about 3 dozen methods. Not all of them tested though. But the skeleton is there.

@cctechwiz

The crazy thing for me is how much JavaScript I have written using an iPad. The Scriptable IDE isn’t fancy, but it does the job.

@rob No. I got busy with work work, side work, and house work. 🤣 it’s still on my todo list though 🤞🏻

@cctechwiz
I understand. Will post the code and send the link here when I’m able. The one issue is that I haven’t put shortcut hooks on it yet. So I’m only testing by calling the JavaScript inside Scriptable.

My first goal is to write my Apple calendar to my daily note in Scriptable. That’ll be a huge quality of life improvement for me.

Yes. I'm just loading the file into memory, scanning it for what I want to do, and then writing it back with changes. There is no reason to really call Obsidian at this point.

@cctechwiz

I'd say that is one of the big benefits of Actions for Obsidian in that it kicks off the native syncing. That said, Obsidian syncing has been a real pain in my behind. I tried rolling my own sync using Remotely Save. It worked, but was painful.

So I paid for Obsidian Sync. And wow - in my experience it is horrible. So many duplicated files. It says I have used a GB when my vault is tens of MB. Obsidian Sync is one of the slowest and worst services I remember paying for.

@cctechwiz

@rob when I get you right, it‘s possible with iOS Shortcuts already. I have a script, allowing to save coordinates in Frontmatter and in mapview integrated in a new note.
Want to add also the local weather with wttr.in, but getting stuck here.

@TimmSL

What’s the issue? If you can generate the text, you can modify this shortcut to write it to a file.

Are you stuck on collecting the weather info or writing the file?

One tricky part is iOS will only write .txt files, so you have to rename it to .md as the last step.