Permission problem opening file in iA Writer via Applescript

Hi all,

I tried to figure out how I could open .md files from my Obsidian vault in iA Writer via KM. Now I got a problem I couldn't solve: The macro works fine, if the file was opened once in iA Writer, but if I use it with a "new" file, I get an error message from iA Writer that the file couldn't be opened due to the lack of permissions.

The same behavior is reproducible when I run the AppleScript within the ScriptEditor and for files in different folders, not just the Obsidian vault. I have granted iA Writer full disc access and already run a "chmod -R 755" on the vault folder.

Has anyone of you a tip for me how to solve this? Thanks in advance!


Open in iAWriter.kmmacros (3.0 KB)

Does iA Writer also give you the same error when you open a new file manually inside the iA Writer app? Or only when you run this script?

I don't have any of the apps you are talking about, and I'm not a whiz withe AppleScript, but I want to help if I can. That's the only question I can muster right now.

I can open the files in the app without problems. After I have done this, the script runs fine but just for this particular file.

Can you perform the terminal command "ls -l" on the file before and after it's been "touched" by the app. This will show the permissions, group and owner of the file. Do any of these attributes change?

Good idea! Brings some interesting things up:

Before opened in iA Writer:

MacBook-Air-von-Johannes:~ jbedenbender$ ls -l 
-rw-r--r--  1 jbedenbender  staff  0 10 Feb 20:44

After opened in iA Writer:

MacBook-Air-von-Johannes:~ jbedenbender$ ls -l 
-rw-r--r--@ 1 jbedenbender  staff  0 10 Feb 20:46

There are some extended attributes set, this seems to make the difference.

MacBook-Air-von-Johannes:~ jbedenbender$ xattr -l ?kb ??<!Ʉ.??/?ֻ???
\???Xf?Z?li?^+????Ѕ?7m?F??:?<???N?0W?? 0086;62056b86;iA Writer;
net.ia.writer.selectedRange: bplist00F{0, 0}
net.ia.writer.visibleRange: bplist00F{0, 0}

I tested my script with BBEdit instead of iA Writer and it works perfectly fine on every file.

So it seems to me that this is an iA Writer problem and I will search there for a solution. Thanks for your help nonetheless!

For the sake of completeness here is the solution: I reached out for the iA Writer support and they gave me the following hints:

While support for scripting falls a bit outside our scope of support, it sounds like this is a sandboxing issue.

If the folder containing the file is added to iA Writer's Library, you will likely not see this when attempting to launch your file since iA Writer will have the necessary permissions to access the file.

Alternatively, you might be able to accomplish your intended task by using instead a shell script in Apple Script. For example, something like this for your test file:

do shell script "open /Users/jbedenbender/ -a \"iA Writer\""

The first solution worked out for me, but I think there will be times when the second one becomes handy.

Good job. I'm happy that you are happy. (IHTYAH.)

1 Like